| This is not an issue. The JOIN is expected for multiple reasons: 1. At first, the association fetch strategy was not declared, so it was EAGER by default. 2. Even after changing it to LAZY, the JOIN comes from trying to project the child association. The JPA multiselect is meant for DTO projections, aggregates, reports, not for selecting entities as illustrated in the example attached to this issue. Therefore, the query should be written like this:
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" ).get( "id" ) );
TypedQuery<Tuple> typedQuery = s.createQuery( cq );
List<Tuple> result = typedQuery.getResultList();
and it will work just fine. Or, it could be written like this if associations need to be fetched:
CriteriaQuery<Parent> cq = cb.createQuery( Parent.class );
Root<Parent> root = cq.from( Parent.class );
root.fetch( "child" );
cq.select( root );
TypedQuery<Parent> typedQuery = s.createQuery( cq );
List<Parent> result = typedQuery.getResultList();
For these reasons, I'm closing this issue. |