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