use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Child in project eclipselink by eclipse-ee4j.
the class AdvancedJunitTest method testBUG241388.
public void testBUG241388() {
Integer id = null;
int childCount;
// // PART 1 ////
EntityManager em1 = createEntityManager();
beginTransaction(em1);
try {
Parent p0 = new Parent(false);
em1.persist(p0);
em1.flush();
id = p0.getId();
Parent p1 = em1.find(Parent.class, id);
p1.setSerialNumber("12345678");
Child cs_1_1 = new Child();
p1.addChild(cs_1_1);
em1.flush();
Child cs_1_2 = new Child();
p1.addChild(cs_1_2);
em1.flush();
Parent chassis2 = em1.find(Parent.class, id);
Child cs_2_1 = new Child();
chassis2.addChild(cs_2_1);
em1.flush();
commitTransaction(em1);
} catch (Exception e) {
e.printStackTrace();
rollbackTransaction(em1);
} finally {
Parent pa = em1.find(Parent.class, id);
childCount = pa.getChildren().size();
closeEntityManager(em1);
}
// // PART 2 ////
Parent chassis = createEntityManager().find(Parent.class, id);
assertTrue("The same number of children where not returned from the cache", childCount == chassis.getChildren().size());
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Child in project eclipselink by eclipse-ee4j.
the class AdvancedJunitTest method testLazyToInterface.
/**
* Test that instantiating a lazy relationship to an interface works.
* This requires that the weaving indirection policy find to real field correctly.
*/
public void testLazyToInterface() {
EntityManager em = createEntityManager();
beginTransaction(em);
Parent parent = null;
Child child = null;
try {
parent = new Parent(false);
child = parent.getChildren().get(0);
em.persist(parent);
commitTransaction(em);
} finally {
closeEntityManagerAndTransaction(em);
}
clearCache();
em = createEntityManager();
beginTransaction(em);
try {
child = em.find(Child.class, child.getId());
((JpaEntityManager) em.getDelegate()).copy(child, new CopyGroup());
commitTransaction(em);
} finally {
closeEntityManagerAndTransaction(em);
}
}
Aggregations