We are using OpenJPA 2.3.0. We have DAO entities with Date type properties and with relations to other DAO entities. We retrieve the data from the database, map it to similar DTO objects and pass those across the wire. We also receive the same DTO objects over the wire, map those back to the DAO and persist the data to the DB.
We experienced the problem with Date fields where when the client NULLs the Date field and we persist the change, OpenJPA does not update the field to NULL because it can't be sure that the value was loaded in the first place.
We tried including this persistence.xml setting:
<property name="openjpa.DetachState" value="fetch-groups"/>
Which fixed the Date saving problem, but then caused a problem on other entities. This problem was with the DAO entities that referenced other DAO entities (with a ManyToOne or OneToOne reference etc.). As these referenced entities were not loaded initially, when we persisted the parent entity the child reference would be NULL and therefore the OpenJPA would delete the child reference (cascading persistence was turned on for saving).
To get around this second problem we turned on eager loading for those child entities, but that caused a lot of extra data to be loaded when it wasn't always necessary. We need to turn this off as it causes too high a load on the DB.
I'm curious to know if anyone else has found a more elegant solution to saving NULL values for Date properties on DAO entities that are serialized.
Class for reference:
@Entity
public class Parent implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "child", fetch = FetchType.EAGER)
private List<ChildType> children;
@Temporal(TemporalType.DATE)
private Date endDate;
...