aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to use IN clause in HQL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to use IN clause in HQL?" Watch "How to use IN clause in HQL?" New topic
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: 17259
    
    6

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 :-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use IN clause in HQL?