Hi Arjan,
On 1/6/14 3:25 PM, arjan.tijms_at_gmail.com wrote:
> Hi,
>
> 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"
>
In the above example, were you expecting the query result to be a
singleResult or a resultList?
> I wonder what the reason for this limitation is.
>
The restriction was made for conformance to "standard" SQL,
which doesn't support collection-valued results in the select list.
> In practice I found this to be quite a limitation when needing to
> create e.g. DTOs from an entity.
>
BTW, I had hoped to address the DTO creation issue with the
copy-graph proposal, but unfortunately we ran out of bandwidth to
reach consensus on that in JPA 2.1
> 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?
>