Hello guys,
I have an Entity CustomerProgram that has a List<CustomerProgramEntries> property, like this:
Code:
@OneToMany(mappedBy = "customerProgram", orphanRemoval = true, fetch = FetchType.LAZY, cascade = javax.persistence.CascadeType.ALL)
@Where(clause = "status='ACTIVE' or status='PENDING' or status='TERMINATED'")
@OrderBy(clause = "uid asc")
public List<CustomerProgramEntry> getCustomerProgramEntries() {
/*check if composition is valid*/
validateCustomerProgramEntries();
return this.customerProgramEntries;
}
The @Where annotation works perfectly well when selecting, but when updating an item in this list to a different status (which does not meet the @Where clause, e.g. 'INACTIVE'), and subsequently merging the CustomerProgram, the updated CustomerPogramEntry remains in the list whereas (I assumed) it should not since it has gotten a different status than specified in the @Where annotation.
The workaround is calling em.flush afther merging (em.merge) and then calling em.refresh on the customerProgram entity to force a reload of the list. As you guys can read I'm using EntityManager rather than Hibernate Session.
For me, this doesnt feel quite right. I had expected the merge operation to cascade on the list<CustomerProgramEntry> property and return the correct db state to me meaning the item should not be in the list anymore.
Can anyone please confirm if this specified behaviour is correct and that my workaround is the only possible solution?
Many thanks,
Kim
PS. Im using JPA 2.1 icw Hibernate 4.3.5-Final