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.");
}
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);
}
}
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;
}
}
Aggregations