By section 18.104.22.168 of the JPA specfification:
"A fetch join has the same join semantics as the corresponding inner or outer
join, except that the related
objects specified on the right-hand side of the join operation are not returned
in the query result or otherwise
referenced in the query. Hence, for example, if department 1 has five
employees, the above query
returns five references to the department 1 entity."
Current ReadAllQuery is designed so that for the above query, only 1 reference
to department will be returned.
We should add a query setting that allows all five instances to be returned and
remove the restriction in the JPQL parser that constructs a ReportQuery for
queries returning 1 item and do a fetch join.
String baseVariable = getParseTree().getFromNode().getFirstVariable();
if (!context.isRangeVariable(baseVariable) ||
(context.getFetchJoins(baseVariable) != null))
This is important because when
GLASSFISH-1519 is checked in, most queries that select
only one attribute will be ReadAllQueries instead of ReportQueries. Because of
the restriction on Fetch joins, it will be difficult for users to understand
when they will get a ReadAllQuery and when they will get a ReportQuery. This
will affect how well some of the Query hints work for them.
(i.e. We will be able to say: If you are selecting only one thing in your
select clause an it is an entity, the following hints will work.)