query setParameter with List

This is a discussion on query setParameter with List within the Apache forums in Application Servers & Tools category; 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-setParame...76p840676.html Sent from the OpenJPA Users mailing list archive at Nabble.com....

Go Back   Application Development Forum > Application Servers & Tools > Apache

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-05-2008, 03:33 AM
hilal
Guest
 
Default 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-setParame...76p840676.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Reply With Quote
  #2  
Old 09-05-2008, 09:20 AM
Jeremy Bauer
Guest
 
Default Re: query setParameter with List

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 ( ids )");
List<Integer> ids = new ArrayList<Integer>();
ids.add(1);
ids.add(2);
qry.setParameter("pids", pids);
List<Person> people = qry.getResultList();

-Jeremy

Reply With Quote
  #3  
Old 09-08-2008, 07:47 AM
hilal
Guest
 
Default Re: query setParameter with List


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-setParame...6p1057825.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:30 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.