Author
How to use IN clause in HQL?
Ganesh Ramani
Greenhorn
Joined: Aug 07, 2007
Posts: 20
Hi, I am looking to use IN clause in my HQL. I referred some forums and couldnt get an optimal idea for this. One approach i tried is to set the parameter of HQL as shown below: My HQL: SELECT prd FROM ProductORM AS prd WHERE prd.productID in (:selPrdIDs) Java code: hqlQuery.setParameterList("selPrdIDs", prdIdList); //prdIdList is List<Integer> But this resulted in SQLGrammarException: could not execute query ; SQLException : Invalid parameter binding(s) Please help to implement IN clause in HQL... Thanks, Ganesh
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17234
posted Oct 31, 2007 08:39:00
0
That is the best approach. And that code should work. I might be missing something simple in it, but it looks fine to me. I'd only ask to make sure that the List had values and was not null. Mark
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Steven Lawrence Hunter
Greenhorn
Joined: Apr 17, 2008
Posts: 4
Use org.hibernate.Query.setParameterList(), which can handle a Collection or an Object[].
Ganesh Ramani
Greenhorn
Joined: Aug 07, 2007
Posts: 20
Yeah, I discovered that after few day I posted that. Nevertheless, thenks for your support :-)
subject: How to use IN clause in HQL?