persistence@glassfish.java.net

Re: Syntax for "IN" parameter

From: Christopher Delahunt <christopher.delahunt_at_oracle.com>
Date: Mon, 16 Apr 2007 13:52:19 -0400

Hi Scott, Gordon,

Enhancement 2484 already exists requesting collection support.
Unfortunately, supporting this is outside the spec and so portable code
should iterate lists manually.

Best Regards,
Chris

----- Original Message -----
From: "Scott Oaks" <Scott.Oaks_at_Sun.COM>
To: <persistence_at_glassfish.dev.java.net>
Sent: Monday, April 16, 2007 1:19 PM
Subject: RE: Syntax for "IN" parameter


> Hi Gordon --
>
> I will file an enhancement, but I believe that such an enhancement will
> be JPA-provider specific, won't it? I guess it hinges on the
> interpretation of the spec when it says "The input parameter values must
> be LIKE the same abstract schema type of the state_field_path_expression
> type" -- the state field is a string. The individual elements of the
> list would be strings, but the type of the input parameter is a list;
> I'm not sure which would apply.
>
> So if I'm interesting in writing completely portable code, would this be
> expected to work, or would I be expected to iterate my list and do
> individual queries?
>
> -Scott
>
> On Mon, 2007-04-16 at 12:58, Gordon Yorke wrote:
>> Hello Scott,
>> TopLink fully supports provinding a list to a IN function. There may
>> be an issue translating the JPA query parameters to the TopLink
>> parameters. Please file an enhancement request. If you would like you
>> can access the TopLink query directly from the EJBQuery and set the IN
>> parameter list on the TopLink query. If you would like more specifics I
>> would be happy to provide them.
>> --Gordon
>>
>> -----Original Message-----
>> From: Scott.Oaks_at_Sun.COM [mailto:Scott.Oaks_at_Sun.COM]On Behalf Of Scott
>> Oaks
>> Sent: Friday, April 13, 2007 1:33 PM
>> To: persistence_at_glassfish.dev.java.net
>> Subject: Syntax for "IN" parameter
>>
>>
>> I'm trying to use a named query:
>>
>> @NamedQuery(name="findByCountry", query="SELECT c FROM Country c WHERE
>> c.id IN(:listId)")
>>
>> I want to set the parameter to
>>
>> 'UK', 'US', 'France'
>>
>> But nothing I try works. If I do
>> q.setParameter("listId", "US")
>> then I get back the results with only the US (so I know the rest of the
>> code is okay). But q.setParameter("listID", "'UK', 'US', 'France'")
>> fails to retrieve anything, as does q.setParameter("listID", "UK, US,
>> France") and q.setParameter("\"UK\", \"US\", \"France\").
>>
>> -Scott
>