Search in sources :

Example 1 with SuperLargeProject

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject in project eclipselink by eclipse-ee4j.

the class EntityManagerJUnitTestSuite method testCascadePersistToNonEntitySubclass.

// Glassfish bug 1021 - allow cascading persist operation to non-entities
public void testCascadePersistToNonEntitySubclass() {
    EntityManager em = createEntityManager();
    InheritancePolicy ip = getDatabaseSession().getDescriptor(Project.class).getInheritancePolicy();
    boolean describesNonPersistentSubclasses = ip.getDescribesNonPersistentSubclasses();
    ip.setDescribesNonPersistentSubclasses(true);
    beginTransaction(em);
    Employee emp = new Employee();
    emp.setFirstName("Albert");
    emp.setLastName("Einstein");
    SuperLargeProject s1 = new SuperLargeProject("Super 1");
    Collection projects = new ArrayList();
    projects.add(s1);
    emp.setProjects(projects);
    em.persist(emp);
    try {
        commitTransaction(em);
    } catch (Exception e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        fail("Persist operation was not cascaded to related non-entity, thrown: " + e);
    } finally {
        ip.setDescribesNonPersistentSubclasses(describesNonPersistentSubclasses);
        closeEntityManager(em);
    }
}
Also used : LargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.LargeProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SmallProject) Project(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Project) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) ArrayList(java.util.ArrayList) Collection(java.util.Collection) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EntityExistsException(jakarta.persistence.EntityExistsException) OptimisticLockException(jakarta.persistence.OptimisticLockException) RollbackException(jakarta.persistence.RollbackException) PersistenceException(jakarta.persistence.PersistenceException) QueryException(org.eclipse.persistence.exceptions.QueryException) TransactionRequiredException(jakarta.persistence.TransactionRequiredException) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject)

Aggregations

EntityExistsException (jakarta.persistence.EntityExistsException)1 EntityManager (jakarta.persistence.EntityManager)1 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 OptimisticLockException (jakarta.persistence.OptimisticLockException)1 PersistenceException (jakarta.persistence.PersistenceException)1 RollbackException (jakarta.persistence.RollbackException)1 TransactionRequiredException (jakarta.persistence.TransactionRequiredException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 InheritancePolicy (org.eclipse.persistence.descriptors.InheritancePolicy)1 QueryException (org.eclipse.persistence.exceptions.QueryException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)1 Employee (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee)1 LargeProject (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.LargeProject)1 Project (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Project)1 SmallProject (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SmallProject)1 SuperLargeProject (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject)1