• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use IN clause in HQL?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I discovered that after few day I posted that. Nevertheless, thenks for your support :-)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic