persistence@glassfish.java.net

RE: Syntax for "IN" parameter

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Wed, 9 May 2007 16:01:07 -0400

Hello Tim,

Here's an example of executing the query with TopLink.
        Query query2 = em.createQuery("select e from Employee e where e.salary in (:salaryCollection)");
        Vector salaries = new Vector();
        salaries.add(new Integer(30000));
        salaries.add(new Integer(45000));
        salaries.add(new Integer(50000));
        Vector params = new Vector();
        params.add(salaries);
        Collection collection = (Collection)((EntityManagerImpl)em.getDelegate()).getActiveSession().executeQuery(((EJBQuery)query2).getDatabaseQuery(), params);
        if (em.contains(collection.iterator().next())){
                System.out.println("Success");
        }

Note that the query execution must avoid the JPA parameter processing. I believe a bug has been filed to have the parameter processing updated in JPA.
--Gordon

-----Original Message-----
From: Romanowski, Tim [mailto:tim.romanowski_at_lmco.com]
Sent: Saturday, April 28, 2007 6:46 PM
To: persistence_at_glassfish.dev.java.net
Subject: RE: Syntax for "IN" parameter


Gordon,
For the benefit of the rest of us (or maybe just me), would you please
elaborate? Using Toplink would be much more efficient than my current
method of temporarily storing the list and building a query dynamically.

Thanks!
Tim


-----Original Message-----
From: Gordon Yorke [mailto:gordon.yorke_at_oracle.com]
Sent: Monday, April 16, 2007 12:58 PM
To: persistence_at_glassfish.dev.java.net
Subject: RE: Syntax for "IN" parameter

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