use of org.eclipse.persistence.testing.models.jpa.advanced.derivedid.AdminPool in project eclipselink by eclipse-ee4j.
the class AdvancedCompositePKJunitTest method testMapWithDerivedId.
public void testMapWithDerivedId() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = new Employee();
emp.setFirstName("George");
em.persist(emp);
Administrator adminEmp = new Administrator();
adminEmp.setContractCompany("George's consulting");
adminEmp.setEmployee(emp);
em.persist(adminEmp);
Department support = new Department();
support.setLocation("Ottawa");
support.setName("Support");
support.setRole("Support Customers");
em.persist(support);
DepartmentAdminRole depAdmin = new DepartmentAdminRole();
depAdmin.setAdmin(adminEmp);
depAdmin.setDepartment(support);
em.persist(depAdmin);
AdminPool pool = new AdminPool();
pool.setId(1);
pool.addAdmin(depAdmin);
depAdmin.setPool(pool);
em.persist(pool);
em.flush();
em.clear();
clearCache();
pool = em.find(AdminPool.class, pool.getId());
assertTrue("The AdminPool was not found.", pool != null);
assertTrue("The map did not contain the correct elements.", pool.getAdmins().get(depAdmin.buildDepartmentAdminRolePK()) != null);
} catch (Exception e) {
fail("Exception caught while testing maps with derived ids." + e);
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
Aggregations