em.createQuery("SELECT o, p from Order o JOIN o.items i JOIN i.producer p WHERE o.filled = true");
// don't suppress warnings.
List<Object[]> jpqlResults = jpqlQuery.getResultList();
// Get results using Tuple
QueryBuilder qb = em.getQueryBuilder();
CriteriaQuery<Tuple> criteriaQuery = qb.createTupleQuery();
Root<Order> order = criteriaQuery.from(Order.class);
Join<Item, Producer> producer = order.join(Order_.items).join(Item_.producer);
criteriaQuery.select(qb.tuple(order, producer));
criteriaQuery.where(qb.equal(order.get(Order_.filled), Boolean.TRUE));
TypedQuery<Tuple> eq = em.createQuery(criteriaQuery);
List<Tuple> criteriaResults = eq.getResultList();
// Get results using custom class
CriteriaQuery<OrderProducer> constructQuery = qb.createQuery(OrderProducer.class);
Root<Order> order2 = constructQuery.from(Order.class);
Join<Item, Producer> producer2 = order.join(Order_.items).join(Item_.producer);
constructQuery.select(qb.construct(OrderProducer.class, order2, producer2));
constructQuery.where(qb.equal(order2.get(Order_.filled), Boolean.TRUE));
TypedQuery<OrderProducer> typedQuery = em.createQuery(constructQuery);
List<OrderProducer> constructResults = typedQuery.getResultList();
assertEquals(N_ORDERS / 2 * N_ITEMS_PER_ORDER, jpqlResults.size());
assertEquals(N_ORDERS / 2 * N_ITEMS_PER_ORDER, criteriaResults.size());