Search in sources :

Example 1 with Cubicle

use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle in project eclipselink by eclipse-ee4j.

the class AdvancedCompositePKJunitTest method testFailedGetIdenitifier.

// bug 409579
public void testFailedGetIdenitifier() {
    EntityManagerFactory factory = getEntityManagerFactory();
    Cubicle cube = new Cubicle();
    cube.setId(1);
    cube.setCode("a");
    try {
        factory.getPersistenceUnitUtil().getIdentifier(cube);
    } catch (PersistenceException e) {
        return;
    }
    fail("Exception not thrown for call to getIdentifier when empty constructor not available.");
}
Also used : EntityManagerFactory(jakarta.persistence.EntityManagerFactory) PersistenceException(jakarta.persistence.PersistenceException) Cubicle(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle)

Example 2 with Cubicle

use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle in project eclipselink by eclipse-ee4j.

the class JUnitJPQLComplexAggregateTestSuite method complexCountOnJoinedCompositePK.

/**
 * Test case bug 6155093:
 */
public void complexCountOnJoinedCompositePK() {
    EntityManager em = createEntityManager();
    try {
        beginTransaction(em);
        Scientist s = new Scientist();
        s.setFirstName("John");
        s.setLastName("Doe");
        Cubicle c = new Cubicle();
        c.setCode("G");
        c.setScientist(s);
        s.setCubicle(c);
        em.persist(c);
        em.persist(s);
        em.flush();
        // Need to create the expected result manually, because using the
        // TopLink query API would run into the same issue 6155093.
        List<Long> expectedResult = Arrays.asList(1L);
        Collections.sort(expectedResult);
        // COUNT DISTINCT with inner join
        String jpql = "SELECT COUNT(DISTINCT p) FROM Scientist e JOIN e.cubicle p WHERE e.lastName LIKE 'D%'";
        Query q = em.createQuery(jpql);
        List result = q.getResultList();
        Collections.sort(result);
        Assert.assertEquals("Complex COUNT on joined variable composite PK", expectedResult, result);
    } finally {
        rollbackTransaction(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) ReportQuery(org.eclipse.persistence.queries.ReportQuery) Query(jakarta.persistence.Query) Scientist(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Scientist) List(java.util.List) Cubicle(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle)

Example 3 with Cubicle

use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle in project eclipselink by eclipse-ee4j.

the class AdvancedCompositePKJunitTest method testCreateScientists.

public void testCreateScientists() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        Department department = em.merge(em.find(Department.class, m_departmentPK));
        Cubicle cubicle1 = new Cubicle("G");
        em.persist(cubicle1);
        Scientist scientist1 = new Scientist();
        scientist1.setFirstName("Guy");
        scientist1.setLastName("Pelletier");
        scientist1.setCubicle(cubicle1);
        department.addScientist(scientist1);
        em.persist(scientist1);
        Cubicle cubicle2 = new Cubicle("T");
        em.persist(cubicle2);
        Scientist scientist2 = new Scientist();
        scientist2.setFirstName("Tom");
        scientist2.setLastName("Ware");
        scientist2.setCubicle(cubicle2);
        department.addScientist(scientist2);
        em.persist(scientist2);
        Cubicle cubicle3 = new Cubicle("G");
        em.persist(cubicle3);
        Scientist scientist3 = new Scientist();
        scientist3.setFirstName("Gordon");
        scientist3.setLastName("Yorke");
        scientist3.setCubicle(cubicle3);
        department.addScientist(scientist3);
        em.persist(scientist3);
        Cubicle cubicle4 = new Cubicle("J");
        em.persist(cubicle4);
        JuniorScientist jScientist = new JuniorScientist();
        jScientist.setFirstName("Junior");
        jScientist.setLastName("Sao");
        jScientist.setCubicle(cubicle4);
        department.addScientist(jScientist);
        em.persist(jScientist);
        commitTransaction(em);
        m_scientist1PK = scientist1.getPK();
        m_scientist2PK = scientist2.getPK();
        m_scientist3PK = scientist3.getPK();
        m_jScientistPK = jScientist.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) Scientist(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Scientist) JuniorScientist(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.JuniorScientist) Cubicle(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle) JuniorScientist(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.JuniorScientist)

Aggregations

Cubicle (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle)3 EntityManager (jakarta.persistence.EntityManager)2 Scientist (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Scientist)2 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 PersistenceException (jakarta.persistence.PersistenceException)1 Query (jakarta.persistence.Query)1 List (java.util.List)1 ReportQuery (org.eclipse.persistence.queries.ReportQuery)1 Department (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department)1 JuniorScientist (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.JuniorScientist)1