@SuppressWarnings("unchecked")
private void testQueryParentAndChildren(StartEnd startEnd) {
Child11 c11 = newChild11(startEnd, "A", 111);
Long c11Id = c11.getId();
Child12 c12 = newChild12(startEnd, "B", 112, 211, 8.15f, new Embedded1("Embedded1"),
new Child11Many("Child12(2)/Child11Many"));
Long c12Id = c12.getId();
Parent p = newParent(startEnd, "C");
Long pId = p.getId();
Child21 c21 = newChild21(startEnd, "D", 121L);
Long c21Id = c21.getId();
Child22 c22 = newChild22(startEnd, "E", "Child22", Boolean.TRUE, null);
Long c22Id = c22.getId();
Assert.assertEquals(5, countForKind(PARENT_KIND));
if (em.isOpen()) {
em.close();
}
em = emf.createEntityManager();
startEnd.start();
Query q = em.createQuery("select p from " + Parent.class.getName() + " p order by parentStr desc");
List<Parent> r = (List<Parent>)q.getResultList();
Assert.assertEquals(5, r.size());
c22 = (Child22)r.get(0);
Assert.assertEquals(c22Id, c22.getId());
Assert.assertEquals("E", c22.getParentStr());
Assert.assertEquals("Child22", c22.getChild22Str());
Assert.assertEquals(Boolean.TRUE, c22.getValue());
c21 = (Child21)r.get(1);
Assert.assertEquals(c21Id, c21.getId());
Assert.assertEquals("D", c21.getParentStr());
Assert.assertEquals(121L, c21.getChild21Long());
p = r.get(2);
Assert.assertEquals(pId, p.getId());
Assert.assertEquals("C", p.getParentStr());
c12 = (Child12)r.get(3);
Assert.assertEquals(c12Id, c12.getId());
Assert.assertEquals("B", c12.getParentStr());
Assert.assertEquals(new Integer(112), c12.getChild11Integer());
Assert.assertEquals(211, c12.getChild12Int());
Assert.assertEquals(8.15f, c12.getValue());
Assert.assertEquals("Embedded1", c12.getEmbedded1().getStr());
Assert.assertEquals(1, c12.getChild11Manys().size());
c11 = (Child11)r.get(4);
Assert.assertEquals(c11Id, c11.getId());
Assert.assertEquals("A", c11.getParentStr());
Assert.assertEquals(new Integer(111), c11.getChild11Integer());
startEnd.end();
startEnd.start();
q = em.createQuery("select c from " + Child11.class.getName() + " c where child11Integer >= 111");
r = (List<Parent>)q.getResultList();
Assert.assertEquals(2, r.size());
startEnd.end();
startEnd.start();
q = em.createQuery("select c from " + Child12.class.getName() + " c where value >= 8.0");
r = (List<Parent>)q.getResultList();
Assert.assertEquals(1, r.size());
Assert.assertEquals(c12Id, r.get(0).getId());
c12 = (Child12)r.get(0);
Assert.assertEquals("B", c12.getParentStr());
Assert.assertEquals(new Integer(112), c12.getChild11Integer());
Assert.assertEquals(211, c12.getChild12Int());
Assert.assertEquals(8.15f, c12.getValue());
Assert.assertEquals("Embedded1", c12.getEmbedded1().getStr());
Assert.assertEquals(1, c12.getChild11Manys().size());
startEnd.end();
startEnd.start();
q = em.createQuery("select c from " + Child22.class.getName() + " c where value = true");
r = (List<Parent>)q.getResultList();