Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink PreUpdate on OneToOne Relationship not persisted(PreUpdate)
EclipseLink PreUpdate on OneToOne Relationship not persisted [message #1810111] Wed, 31 July 2019 13:34
Sara  Rüegg is currently offline Sara RüeggFriend
Messages: 2
Registered: July 2019
Junior Member
I have a PreUpdate method which gets executed, but when flushing the entityManager the changes on the dependent entity are not persisted.

Following is my minimal (non) working example:

Entities

@Entity
@Table(name = "HOUSE")
public class House {

@Id
@Column(name = "ID")
private long id;

@OneToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "INFO_ID")
private HouseInfo info;

@PreUpdate
protected void komplettiereEingabeWerte() {
info.setCode("TEST");
}

//getters and setters
}

@Entity
@Table(name = "HOUSE_INFO")
public class HouseInfo {

@Id
@Column(name = "ID")
private long id;

@Column(name = "CODE")
private String code;

//getters and setters
}
Testcase

@Test
@Transactional(TransactionMode.ROLLBACK)
public void testPreUpdate() {
House house = entityManager.find(House.class, 1L);
house.setInfo(new HouseInfo());
entityManager.flush();
entityManager.clear();

house = entityManager.find(House.class, 1L);
assertEquals("TEST", house.getInfo().getCode());
}
The Test fails due to an AssertionError on the last line as Code is null.

I am using EclipseLink version 2.7.4 with an Oracle DB (the same behaviour was also observed with an in memory Derby DB) and the Test is running with UnitilsJUnit4 in a SpringApplicationContext.

How can I fix this problem? Thank you.
Previous Topic:NotReadablePropertyException while using SpringData projection
Next Topic:Passing Collection List to In clause in nativeQuery - EclipseLink
Goto Forum:
  


Current Time: Fri Mar 29 11:09:20 GMT 2024

Powered by FUDForum. Page generated in 0.02342 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top