Search in sources :

Example 6 with InheritancePolicy

use of org.eclipse.persistence.descriptors.InheritancePolicy 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 7 with InheritancePolicy

use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.

the class SecurityWhileInitializingClassExtractionMethodTest method setup.

@Override
protected void setup() {
    super.setup();
    expectedException = DescriptorException.securityWhileInitializingClassExtractionMethod("Dummy_Method", new RelationalDescriptor(), new Exception());
    getTestDescriptor().setInheritancePolicy(new InheritancePolicy());
    policy = getTestDescriptor().getInheritancePolicy();
    // need not getClassExtractionMethodName() == null
    // this method does exist in above class
    policy.setClassExtractionMethodName("dummy_Method");
    // need NoSuchMethod thrown from         setClassExtractionMethod(Helper.getDeclaredMethod(getDescriptor().getJavaClass(), getClassExtractionMethodName(), declarationParameters));
    // nice if isChildDescriptor() == false
    policy.setParentClass(null);
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 8 with InheritancePolicy

use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.

the class NoSuchMethodWhileInitializingClassExtractionMethodTest method test.

@Override
public void test() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(NoSuchMethodWhileInitializingClassExtractionMethodTest.class);
    descriptor.setInheritancePolicy(new InheritancePolicy());
    InheritancePolicy policy = descriptor.getInheritancePolicy();
    // need not getClassExtractionMethodName() == null
    // this method does not exist in above class
    policy.setClassExtractionMethodName("Dummy_Method");
    // need NoSuchMethod thrown from         setClassExtractionMethod(Helper.getDeclaredMethod(getDescriptor().getJavaClass(), getClassExtractionMethodName(), declarationParameters));
    // nice if isChildDescriptor() == false
    policy.setParentClass(null);
    try {
        policy.preInitialize((AbstractSession) getSession());
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException)

Example 9 with InheritancePolicy

use of org.eclipse.persistence.descriptors.InheritancePolicy 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 = getServerSession().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 : Project(org.eclipse.persistence.testing.models.jpa.advanced.Project) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject) SpecialHugeProject(org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) EntityExistsException(jakarta.persistence.EntityExistsException) OptimisticLockException(jakarta.persistence.OptimisticLockException) QueryException(org.eclipse.persistence.exceptions.QueryException) TransactionRequiredException(jakarta.persistence.TransactionRequiredException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) SQLException(java.sql.SQLException) RollbackException(jakarta.persistence.RollbackException) NoResultException(jakarta.persistence.NoResultException) PersistenceException(jakarta.persistence.PersistenceException) PersistenceUnitLoadingException(org.eclipse.persistence.exceptions.PersistenceUnitLoadingException) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject)

Example 10 with InheritancePolicy

use of org.eclipse.persistence.descriptors.InheritancePolicy 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 = getServerSession().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 : Project(org.eclipse.persistence.testing.models.jpa.advanced.Project) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject) SpecialHugeProject(org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) ArrayList(java.util.ArrayList) CustomerCollection(org.eclipse.persistence.testing.models.jpa.relationships.CustomerCollection) Collection(java.util.Collection) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) EntityExistsException(jakarta.persistence.EntityExistsException) OptimisticLockException(jakarta.persistence.OptimisticLockException) QueryException(org.eclipse.persistence.exceptions.QueryException) TransactionRequiredException(jakarta.persistence.TransactionRequiredException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) SQLException(java.sql.SQLException) RollbackException(jakarta.persistence.RollbackException) NoResultException(jakarta.persistence.NoResultException) PersistenceException(jakarta.persistence.PersistenceException) PersistenceUnitLoadingException(org.eclipse.persistence.exceptions.PersistenceUnitLoadingException) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject)

Aggregations

InheritancePolicy (org.eclipse.persistence.descriptors.InheritancePolicy)22 Collection (java.util.Collection)7 EntityExistsException (jakarta.persistence.EntityExistsException)6 EntityManager (jakarta.persistence.EntityManager)6 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)6 OptimisticLockException (jakarta.persistence.OptimisticLockException)6 PersistenceException (jakarta.persistence.PersistenceException)6 RollbackException (jakarta.persistence.RollbackException)6 TransactionRequiredException (jakarta.persistence.TransactionRequiredException)6 ArrayList (java.util.ArrayList)6 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)6 QueryException (org.eclipse.persistence.exceptions.QueryException)6 ValidationException (org.eclipse.persistence.exceptions.ValidationException)6 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)6 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)5 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)4 InvalidObject (org.eclipse.persistence.internal.helper.InvalidObject)4 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)4 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)4 TestProblemException (org.eclipse.persistence.testing.framework.TestProblemException)4