use of org.hibernate.jpa.test.metamodel.ThingWithQuantity in project hibernate-orm by hibernate.
the class AbstractPathImplTest method prepareTestData.
@Before
public void prepareTestData() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Thing thing = new Thing();
thing.setId("thing1");
thing.setName("A Thing");
em.persist(thing);
thing = new Thing();
thing.setId("thing2");
thing.setName("Another Thing");
em.persist(thing);
ThingWithQuantity thingWithQuantity = new ThingWithQuantity();
thingWithQuantity.setId("thingWithQuantity3");
thingWithQuantity.setName("3 Things");
thingWithQuantity.setQuantity(3);
em.persist(thingWithQuantity);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.jpa.test.metamodel.ThingWithQuantity in project hibernate-orm by hibernate.
the class TreatKeywordTest method testSelectSubclassPropertyFromDowncast.
@Test
public void testSelectSubclassPropertyFromDowncast() {
EntityManager em = getOrCreateEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Integer> criteria = builder.createQuery(Integer.class);
Root<Thing> root = criteria.from(Thing.class);
Root<ThingWithQuantity> subroot = builder.treat(root, ThingWithQuantity.class);
criteria.select(subroot.<Integer>get("quantity"));
em.createQuery(criteria).getResultList();
em.close();
}
Aggregations