• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Count query having IN clause in Hibernate

 
Devesh Chanchlani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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."
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.
====================
 
Ganesh Ramani
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
  • 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."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic