You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by hilal <hi...@yahoo.com> on 2008/09/05 09:33:06 UTC
query setParameter with List
hey everybody,
I am trying to write a query like this:
SELECT * from person WHERE personId IN ( ?1 )
the query should take just one parameter, List of personIds :
util.List<Integer>
so it becomes: query.setParameter(idList);
how i can do this?
or is it possible with openJpa?
--
View this message in context: http://n2.nabble.com/query-setParameter-with-List-tp840676p840676.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: query setParameter with List
Posted by lavanyapmr <la...@gmail.com>.
I've found this thread when I'm searching for the similar issue.
So, is it not possible to pass list of values as parameter in named native
query?
--
View this message in context: http://openjpa.208410.n2.nabble.com/query-setParameter-with-List-tp840676p5977474.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: query setParameter with List
Posted by hilal <hi...@yahoo.com>.
thanks a lot,
now it works.
I was using native query not hql query. that's why it didn't work.
--
View this message in context: http://n2.nabble.com/query-setParameter-with-List-tp840676p1057825.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: query setParameter with List
Posted by Jeremy Bauer <te...@gmail.com>.
Hi there.
OpenJPA does indeed support queries that use a list parameter as query
criteria. Here's a snippet of code that uses a JPQL query to return
those Person entities which have a matching id in a list of personId.
Query qry = em.createQuery("SELECT p FROM Person p WHERE p.personId
IN ( :pids )");
List<Integer> ids = new ArrayList<Integer>();
ids.add(1);
ids.add(2);
qry.setParameter("pids", pids);
List<Person> people = qry.getResultList();
-Jeremy