Search in sources :

Example 1 with Competency

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;
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) Department(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department) Competency(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency)

Example 2 with Competency

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"));
        }
    }
}
Also used : AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) EntityManager(jakarta.persistence.EntityManager) Department(org.eclipse.persistence.testing.models.jpa.advanced.Department) Competency(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency) Test(org.junit.Test)

Example 3 with Competency

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);
    }
}
Also used : Department(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department) EntityManager(jakarta.persistence.EntityManager) Competency(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency) CopyGroup(org.eclipse.persistence.sessions.CopyGroup)

Aggregations

EntityManager (jakarta.persistence.EntityManager)3 Competency (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Competency)3 Department (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department)2 AttributeGroup (org.eclipse.persistence.queries.AttributeGroup)1 CopyGroup (org.eclipse.persistence.sessions.CopyGroup)1 Department (org.eclipse.persistence.testing.models.jpa.advanced.Department)1 Test (org.junit.Test)1