use of org.eclipse.persistence.testing.models.jpa.advanced.derivedid.DepartmentAdminRolePK in project eclipselink by eclipse-ee4j.
the class AdvancedCompositePKJunitTest method testDepartmentAdmin.
public void testDepartmentAdmin() {
String location = "Ottawa";
String depName = "New Product Research";
String depRole = "R&D new technologies";
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 newProductResearch = new Department();
newProductResearch.setLocation(location);
newProductResearch.setName(depName);
newProductResearch.setRole(depRole);
em.persist(newProductResearch);
DepartmentAdminRole depAdmin = new DepartmentAdminRole();
depAdmin.setAdmin(adminEmp);
depAdmin.setDepartment(newProductResearch);
em.persist(depAdmin);
commitTransaction(em);
DepartmentAdminRolePK depAdminPk = new DepartmentAdminRolePK(depName, depRole, location, adminEmp.getEmployee().getId());
DepartmentAdminRole cacheObject = em.find(DepartmentAdminRole.class, depAdminPk);
assertTrue("Find did not return the DepartmentAdminRole", cacheObject != null);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
} finally {
closeEntityManager(em);
}
}
Aggregations