use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Office in project eclipselink by eclipse-ee4j.
the class AdvancedCompositePKJunitTest method testJoinColumnSharesPK.
public void testJoinColumnSharesPK() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = createEntityManager();
beginTransaction(em);
org.eclipse.persistence.descriptors.ClassDescriptor descriptor = getServerSession().getDescriptor(Office.class);
try {
Department department = new Department();
department.setName("DEPT B");
department.setRole("ROLE B");
department.setLocation("LOCATION B");
em.persist(department);
Office office = new Office();
office.setId(1);
office.setLocation("LOCATION B");
office.setDepartment(department);
em.persist(office);
department.getOffices().add(office);
em.flush();
clearCache();
office = em.find(Office.class, new OfficePK(1, "LOCATION B"));
department = em.find(Department.class, new DepartmentPK("DEPT B", "ROLE B", "LOCATION B"));
assertTrue("Office's department not properly persisted", office.getDepartment() != null);
assertTrue("Department's offices not properly persisted", department.getOffices().size() > 0);
} catch (Exception e) {
fail("Exception thrown while inserting an object with a read-only column in a foreign key." + e);
} finally {
rollbackTransaction(em);
}
}
Aggregations