Skip to main content

[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?

  • From: Linda DeMichiel <linda.demichiel@...>
  • To: users@...
  • Subject: [jpa-spec users] Re: Reason for limiting select clause to single-valued expression?
  • Date: Wed, 08 Jan 2014 11:59:00 -0800
  • Organization: Oracle Corporation

Hi Arjan,

On 1/6/14 3:25 PM, arjan.tijms@... 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?



[jpa-spec users] Reason for limiting select clause to single-valued expression?

arjan.tijms 01/06/2014

[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?

Kevin Sutter 01/07/2014

[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?

arjan tijms 01/07/2014

[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?

Linda DeMichiel 01/08/2014

[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?

arjan tijms 01/09/2014

[jpa-spec users] Re: Reason for limiting select clause to single-valued expression?

Linda DeMichiel 01/10/2014
 
 
Close
loading
Please Confirm
Close