use of org.eclipse.persistence.testing.models.jpa.advanced.LargeProject in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testVersionUpdateForOwnedMappings.
public void testVersionUpdateForOwnedMappings() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = em.find(Employee.class, empId);
int currentVersion = emp.getVersion();
assertNotNull("The employee was not found for Id.", empId);
emp.getResponsibilities().add("UpdateVersionField");
commitTransaction(em);
assertTrue("Did not increment version for change to direct collection", emp.getVersion() == ++currentVersion);
beginTransaction(em);
emp = em.find(Employee.class, empId);
emp.getDealers().add(em.merge(new Dealer("update", "version")));
commitTransaction(em);
assertTrue("Did not increment version for change to uni-directional one to many with join table", emp.getVersion() == ++currentVersion);
beginTransaction(em);
emp = em.find(Employee.class, empId);
emp.getProjects().add(em.merge(new LargeProject("versionUpdate")));
commitTransaction(em);
assertTrue("Did not increment version for change to owned ManyToMany", emp.getVersion() == ++currentVersion);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
// Re-throw exception to ensure stacktrace appears in test result.
throw e;
}
closeEntityManager(em);
}
Aggregations