beginTxn();
Query q = em.createQuery(
"select from " + grandchildClass.getName() + " b where aString = :p");
q.setParameter("p", "a2");
Grandchild grandchild = (Grandchild) q.getResultList().get(0);
assertEquals(grandchildClass, grandchild.getClass());
assertEquals("a2", grandchild.getAString());
assertEquals("b1", grandchild.getBString());
assertEquals("c2", grandchild.getCString());
q = em.createQuery(
"select from " + grandchildClass.getName() + " b where bString = :p");
q.setParameter("p", "b2");
grandchild = (Grandchild) q.getSingleResult();
assertEquals(grandchildClass, grandchild.getClass());
assertEquals("a2", grandchild.getAString());
assertEquals("b2", grandchild.getBString());
assertEquals("c3", grandchild.getCString());
q = em.createQuery(
"select from " + grandchildClass.getName() + " b where cString = :p");
q.setParameter("p", "c2");
grandchild = (Grandchild) q.getSingleResult();
assertEquals(grandchildClass, grandchild.getClass());
assertEquals("a2", grandchild.getAString());
assertEquals("b1", grandchild.getBString());
assertEquals("c2", grandchild.getCString());
List<Grandchild> grandkids = ((List<Grandchild>) em.createQuery(
"select from " + grandchildClass.getName() + " b where aString = 'a2' order by bString desc").getResultList());
assertEquals(3, grandkids.size());
assertEquals(e2.getKey().getId(), grandkids.get(0).getId().longValue());