use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency in project eclipselink by eclipse-ee4j.
the class AdvancedCompositePKJunitTest method testCreateDepartment.
public void testCreateDepartment() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
// make sure the department is not left from the previous test run
em.createQuery("DELETE FROM Department d WHERE d.name = 'DEPT A' AND d.role = 'ROLE A' AND d.location = 'LOCATION A'").executeUpdate();
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
clearCache();
closeEntityManager(em);
em = createEntityManager();
beginTransaction(em);
try {
Department department = new Department();
department.setName("DEPT A");
department.setRole("ROLE A");
department.setLocation("LOCATION A");
Competency competency = new Competency();
competency.description = "Manage groups";
competency.rating = 9;
department.addCompetency(competency);
em.persist(department);
commitTransaction(em);
m_departmentPK = department.getPK();
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency in project eclipselink by eclipse-ee4j.
the class NestedFetchGroupTests method dynamicFetchGroup_ElementCollection.
@Test
public void dynamicFetchGroup_ElementCollection() {
EntityManager em = createEntityManager();
AttributeGroup compt = new AttributeGroup(null, Competency.class, true);
compt.addAttribute("description");
AttributeGroup fg = new AttributeGroup(null, org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department.class, true);
fg.addAttribute("competencies", compt);
clearCache();
Collection<org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department> results = em.createQuery("select d from Department d").setHint(QueryHints.FETCH_GROUP, fg.toFetchGroup()).getResultList();
for (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department dept : results) {
assertFalse("Collection fetched: scientists, fg ignored", ((FetchGroupTracker) dept)._persistence_isAttributeFetched("scientists"));
assertFalse("Collection fetched: offices, fg ignored", ((FetchGroupTracker) dept)._persistence_isAttributeFetched("offices"));
assertTrue("Collection not fetched: competencies, fg ignored", ((FetchGroupTracker) dept)._persistence_isAttributeFetched("competencies"));
for (Competency embeded : dept.getCompetencies()) {
assertTrue("Element attribute not loaded: description, fg ignored", ((FetchGroupTracker) embeded)._persistence_isAttributeFetched("description"));
}
dept.getScientists().size();
assertTrue("Collection not fetched: scientists, fg ignored", ((FetchGroupTracker) dept)._persistence_isAttributeFetched("scientists"));
assertTrue("Collection not fetched: offices, fg ignored", ((FetchGroupTracker) dept)._persistence_isAttributeFetched("offices"));
assertTrue("Collection not fetched: competencies, fg ignored", ((FetchGroupTracker) dept)._persistence_isAttributeFetched("competencies"));
for (Competency embeded : dept.getCompetencies()) {
embeded.getRating();
assertTrue("Element attribute not loaded: description, fg ignored", ((FetchGroupTracker) embeded)._persistence_isAttributeFetched("description"));
}
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency in project eclipselink by eclipse-ee4j.
the class AdvancedCompositePKJunitTest method testCopyAggregateCollection.
// Bug 406957 - Copy fails on AggregateCollectionMapping and on map with @MapKeyColumn
public void testCopyAggregateCollection() {
Department department = new Department();
department.setName("DEPT AggregateCollection");
department.setRole("ROLE AggregateCollection");
department.setLocation("LOCATION AggregateCollection");
Competency competency = new Competency();
competency.description = "Manage groups";
competency.rating = 9;
department.addCompetency(competency);
EntityManager em = createEntityManager();
CopyGroup privatelyOwned = new CopyGroup();
Department departmentCopy = (Department) JpaHelper.getEntityManager(em).copy(department, privatelyOwned);
if (departmentCopy.getCompetencies().size() != department.getCompetencies().size()) {
fail("departmentCopy.getCompetencies().size() = " + departmentCopy.getCompetencies().size() + "; " + department.getCompetencies().size() + " was expected");
}
if (departmentCopy.getCompetencies() == department.getCompetencies()) {
fail("departmentCopy.getCompetencies() == department.getCompetencies()");
}
Competency copmetencyCopy = departmentCopy.getCompetencies().iterator().next();
if (!competency.description.equals(copmetencyCopy.description)) {
fail("competency.descripton = " + competency.description + "; but copmetencyCopy.description = " + copmetencyCopy.description);
}
}
Aggregations