persistence@glassfish.java.net

Re: Getting multiple objects by id

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Thu, 04 Mar 2010 21:09:21 -0500

Fabulous! It works just as I had hoped for. Thanks very much Mitesh.

On 03/04/2010 07:00 PM, Mitesh Meswani wrote:
> With JPA 2.0, you can do that. See section 4.6.9 of spec for more
> details.
>
> On 3/4/2010 2:37 PM, Farrukh Najmi wrote:
>> Hi Guys,
>>
>> I am writing a subscription selector query that needs to match any
>> number of objects as specified by a collection of object ids.
>> Conceptually the query looks like:
>>
>> SELECT DISTINCT Object(p) FROM com.acme.Foo foo WHERE foo.id IN (
>> id1, id2, id3, .... )
>>
>> The problem is that the EJBQL grammar:
>>
>> http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/EJBQL5.html
>>
>> does not seem to allow for a collection of strings as a positional
>> parameter within an IN statement.
>>
>> What would have worked but is not supported by the grammar is:
>>
>> SELECT DISTINCT Object(p) FROM com.acme.Foo foo WHERE foo.id IN (
>> :idList )
>>
>> Where idList could be of type List<String> supplied as a named
>> parameter when invoking the query.
>>
>> Is there another way to solve my problem that is scalable and
>> performs well too? Note that my idList could get quite large.
>>
>> Thanks for your help.
>>
>


-- 
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com