• 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

Problem with Count query having IN clause in Hibernate

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,

I am using a namedQuery in Hibernate for Count having IN clause, as follows:

SELECT COUNT(*)
FROM table1
col1 IN ( :List1 ) AND
col2 IN ( :List2 )

I am providing the bind parameters as java.util.List.
Still I donot get any result or even any exception.
I am using Hibernate 3.
Will Hibernate not support a Count query with IN clause having bind parameters ?

=====================
Devesh Chanchlani
=====================

"The journey of a thousand miles begins beneath one's feet."
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shouldn't you add a 'where', like this.

SELECT COUNT(*)
FROM table1
where col1 IN ( :List1 ) AND
col2 IN ( :List2 )
[ October 24, 2007: Message edited by: Arun Kumarr ]
 
Devesh Chanchlani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
There was a where initially, which I apparently missed out.The problem however got resolved.
The mistake was, I was setting the bind parameters using the setBingParameter funtion instead of setBindParameterList.

====================
Devesh Chanchlani.
====================
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Devesh Chanchlani,

I am too stuck with the IN clause usage in HQL. BTW, I am using Hibernate 3.1 and couldn't find the method you specified "setBindParameterList".

Please write back as how you implemented IN clause in the Java program for setting the parameter binding???

Ganesh
 
Devesh Chanchlani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ganesh,

I regret, its my mistake. The function used is "Query.setParameterList".

All you need to do is, for the IN clause, in the named query or HQL query, specify the parameter as "IN ( aram )", and set the parameter in your DAO method using query.setParameterList("param", paramList);

The paramList variable could be any List/Set.

Sorry for the inappropriate prior information.

=====================
Devesh Chanchlani.
=====================

"A positive attitude may not solve all problems, but it'll annoy enough people to make it worth the effort."
reply
    Bookmark Topic Watch Topic
  • New Topic