Search in sources :

Example 1 with SuperLargeProject

use of org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.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();
    // added new setting for bug 237281
    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.composite.advanced.member_3.LargeProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.SuperLargeProject) Project(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.Project) SmallProject(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.SmallProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) Employee(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_2.Employee) ArrayList(java.util.ArrayList) Collection(java.util.Collection) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) 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.composite.advanced.member_3.SuperLargeProject)

Example 2 with SuperLargeProject

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

the class EntityManagerJUnitTestSuite method testExceptionForPersistNonEntitySubclass.

// Bug 237281 - ensure we throw the correct exception when trying to persist a non-entity subclass of an entity
public void testExceptionForPersistNonEntitySubclass() {
    EntityManager em = createEntityManager();
    Exception caughtException = null;
    try {
        beginTransaction(em);
        em.persist(new SuperLargeProject());
    } catch (IllegalArgumentException e) {
        caughtException = e;
    } finally {
        rollbackTransaction(em);
        closeEntityManager(em);
    }
    if (caughtException == null) {
        fail("Caught an incorrect exception when persisting a non entity.");
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) 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.composite.advanced.member_3.SuperLargeProject)

Example 3 with SuperLargeProject

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

the class EntityManagerJUnitTestSuite method testEnabledPersistNonEntitySubclass.

// bug 237281 - ensure seeting InheritancePolicy to allow non-entity subclasses to be persisted as their
// superclass works
public void testEnabledPersistNonEntitySubclass() {
    EntityManager em = createEntityManager();
    InheritancePolicy ip = getDatabaseSession().getDescriptor(Project.class).getInheritancePolicy();
    boolean describesNonPersistentSubclasses = ip.getDescribesNonPersistentSubclasses();
    ip.setDescribesNonPersistentSubclasses(true);
    beginTransaction(em);
    SuperLargeProject s1 = new SuperLargeProject("Super 1");
    try {
        em.persist(s1);
    } catch (Exception e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        fail("Persist operation was not cascaded to related non-entity, thrown: " + e);
    } finally {
        rollbackTransaction(em);
        ip.setDescribesNonPersistentSubclasses(describesNonPersistentSubclasses);
        closeEntityManager(em);
    }
}
Also used : LargeProject(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.LargeProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.SuperLargeProject) Project(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.Project) SmallProject(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.SmallProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) 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.composite.advanced.member_3.SuperLargeProject)

Aggregations

EntityExistsException (jakarta.persistence.EntityExistsException)3 EntityManager (jakarta.persistence.EntityManager)3 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)3 OptimisticLockException (jakarta.persistence.OptimisticLockException)3 PersistenceException (jakarta.persistence.PersistenceException)3 RollbackException (jakarta.persistence.RollbackException)3 TransactionRequiredException (jakarta.persistence.TransactionRequiredException)3 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)3 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)3 QueryException (org.eclipse.persistence.exceptions.QueryException)3 ValidationException (org.eclipse.persistence.exceptions.ValidationException)3 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)3 TestProblemException (org.eclipse.persistence.testing.framework.TestProblemException)3 SuperLargeProject (org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.SuperLargeProject)3 InheritancePolicy (org.eclipse.persistence.descriptors.InheritancePolicy)2 LargeProject (org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.LargeProject)2 Project (org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.Project)2 SmallProject (org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.SmallProject)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1