EclipseLink PreUpdate on OneToOne Relationship not persisted [message #1810111] |
Wed, 31 July 2019 13:34 |
Sara Rüegg 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.
|
|
|
Powered by
FUDForum. Page generated in 0.02854 seconds