Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use IN clause in HQL?

 
Ganesh Ramani
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steven Lawrence Hunter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use org.hibernate.Query.setParameterList(), which can handle a Collection or an Object[].
 
Ganesh Ramani
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I discovered that after few day I posted that. Nevertheless, thenks for your support :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic