Section 4.8 of the JPA spec defines that a select expression is limited
to a single valued path expression. This is emphasized in the body text
of this section via the following paragraph:
"Note that the SELECT clause must be specified to return only
single-valued expressions. The query below is therefore not valid:
SELECT o.lineItems FROM Order AS o"
I wonder what the reason for this limitation is.
In practice I found this to be quite a limitation when needing to
create e.g. DTOs from an entity.
The effect of selecting a single collection attribute from an entity
can be mimicked by something like
SELECT o.id, lineItem FROM Order AS o join o.lineItems as lineItem
And then aggregating the result manually in Java code.
If this can be done rather easily (but tediously) with manual code, why
shouldn't the persistence provider be able to do this?
[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?