persistence@glassfish.java.net

Getting multiple objects by id

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Thu, 04 Mar 2010 17:37:13 -0500

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