Community
Participate
Working Groups
Created attachment 282044 [details] Junit Test I have to increase the version of the Parent entity when updating/removing a child Entity I have two entities: Parent and Child The Child entity contains the reference to the Parent entity. public class Parent { @Id private String id; @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "parent") private Set<Child> children; .... } public class Child { @Id private String id; @ManyToOne(cascade = { CascadeType.ALL }) @JoinColumns({ @JoinColumn(name = "parent_fk", referencedColumnName = "id") }) private Parent parent; } I remove all the children of a given parent and then force the update version of the parent entity. This does not work if, before doing the look, an flush is performed. Example: flush = true em.getTransaction().begin(); Parent p = em.find(Parent.class, PARENT_ID); Set<Child> children = p.getChildren(); assertEquals(3, children.size()); Child c = em.find(Child.class, "child1"); children.remove(c); if (flush) { em.flush(); } p = em.merge(p); em.lock(p, LockModeType.OPTIMISTIC_FORCE_INCREMENT); em.getTransaction().commit(); p = em.find(Parent.class, PARENT_ID); assertEquals(2, children.size()); assertEquals(2, p.getUpdateVersion());
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink