I found the problem.
I performed a test using an entity with the least mapped relationships:
TblPdtcde.class:
// Mapped Relationships
@OneToMany(mappedBy="tblPdtcde",fetch = FetchType.LAZY)
private Collection<TblScmpdt> tblScmpdts = new ArrayList<TblScmpdt>();
@Test
public void testMergeUnchangedEntityAPIs() {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("status");
EntityManager em = emf.createEntityManager();
TblPdtcde e = em.find(TblPdtcde.class, "F");
// e.getTblScmpdts();
e = ((OpenJPAEntityManager)em).detach(e);
assertNotNull(e);
assertFalse(em.contains(e));
Object eOld = e;
TblPdtcdeDTO dto = copyBean(e, TblPdtcdeDTO.class);
e = copyBean(dto, TblPdtcde.class);
assertNotSame(eOld, e);
em.getTransaction().begin();
em.merge(e);
em.getTransaction().commit();
em.close();
}
The version number increments when I comment out "e.getTblScmpdts();" (which
loads the related TblScmpdt entities).
Copying from the DTO to the entity causes the entity to become dirty,
because the DTO sets the tblScmpdts collection to empty collection instead
of null.
TblPdtcdeDTO:
public Collection getTblScmpdts() {
if (tblScmpdts == null) {
tblScmpdts = new ArrayList();
}
return tblScmpdts;
}
StateManagerImpl.settingObjectField (line 1862) gets called curVal =
Collection<TblScmpdt>, newVal = empty collection.
This therefore triggers a version increment.
This is going to be a tricky one to fix...
--
View this message in context:
http://n2.nabble.com/Non-dirty-entity-version-field-update-SUPER-URGENT%21%21%21-tp1120307p1131090.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.