users@jpa-spec.java.net

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

From: arjan tijms <arjan.tijms_at_gmail.com>
Date: Tue, 7 Jan 2014 23:38:19 +0100

Hi,

On Tue, Jan 7, 2014 at 10:05 PM, Kevin Sutter <sutter_at_us.ibm.com> wrote:

> Hi Arjan,
> I don't recall the history of this restriction, but it's been there since
> Day One of the JPA specification.


Ok, I see.



> Allowing collections to be selected could simplify your scenario below,
> but it also opens other scenarios which might not be as straight forward.
> For example, if we allowed "SELECT o.lineItems...", would we also allow
> traversing this collection? Something like "SELECT o.lineItems.id..."
>

That's true, but if such traversing is deemed to be problematic indeed and
there's thus a good reason for not allowing it, then the spec could perhaps
move the restriction. E.g. saying that multi-valued expressions are
allowed, but may not be traversed.

I guess there could be some more complicated cases even, like traversing
multiple collections "SELECT o.lineItems.elements.id..." etc.


Off the top of my head, I don't see why this restriction would have to stay
> in place. I'd suggest opening a "feature request" and then it could be
> evaluated when we start working on JPA 2.2 (or 3.0)...


Thanks, I'll do that. Is there already an estimation btw on when the work
for the next JPA version could possibly start?

Kind regards,
Arjan Tijms




>
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- Kevin Sutter
>
>
>
> <arjan.tijms_at_gmail.com> wrote on 01/06/2014 05:25:00 PM:
>
> > From: <arjan.tijms_at_gmail.com>
> > To: users_at_jpa-spec.java.net,
> > Date: 01/06/2014 05:30 PM
> > Subject: [jpa-spec users] Reason for limiting select clause to
> > single-valued expression?
> >
> > 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"
> >
> > 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?
> >
>