| Réda Housni Alaoui Jens Schauder For the sake of completion, I tested it with Tuple and it works like a charm:
CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createQuery( Tuple.class );
Root<Parent> parentRoot = cq.from( Parent.class );
cq.multiselect( parentRoot.get( "id" ), parentRoot.get( "child" ) );
TypedQuery<Tuple> typedQuery = s.createQuery( cq );
List<Tuple> result = typedQuery.getResultList();
As for constructor expressions, Hibernate considers the entity identifier only when you try to project that into a DTO. Since JPA does not mention this use case, it's not supported. Therefore, you are better of using the Tuple instead. |