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);
}
}
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.");
}
}
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);
}
}
Aggregations