Search in sources :

Example 36 with LargeProject

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) Dealer(org.eclipse.persistence.testing.models.jpa.advanced.Dealer) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)

Aggregations

LargeProject (org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)36 EntityManager (jakarta.persistence.EntityManager)33 SmallProject (org.eclipse.persistence.testing.models.jpa.advanced.SmallProject)24 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)23 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)22 List (java.util.List)15 Project (org.eclipse.persistence.testing.models.jpa.advanced.Project)14 SuperLargeProject (org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject)13 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)12 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)11 HugeProject (org.eclipse.persistence.testing.models.jpa.advanced.HugeProject)11 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)9 ReportQuery (org.eclipse.persistence.queries.ReportQuery)9 SpecialHugeProject (org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject)9 Query (jakarta.persistence.Query)8 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 PersistenceException (jakarta.persistence.PersistenceException)4 TypedQuery (jakarta.persistence.TypedQuery)3