-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: get total count from a subquery
PostPosted: Thu Nov 27, 2003 3:15 pm 
Newbie

Joined: Mon Oct 06, 2003 2:20 pm
Posts: 10
Hi,

I want to get the total number of records of a query.
My query is like this:
"from P p where p.userID in (:userIDs) ";

the userIDs is a list of keys.

====================

i tried to do the following to get the total number of record, but it doesn't work for my case.

String request =
"select count(*) from P p where p.userID in "+ userIDs;

count = ( (Integer) ses.iterate(request).next()).intValue();

It only works if my query based on a single userID using '=userID', but not work if I use 'in userIDs'.

Thanks for the advise.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 4:22 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
1. you better use .list() instead of .iterate()
2. are you sure you constructing correct query? Concatinating parameters to the query is not the best idea. You should use query.setParameterList() instead


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
Query q = s.createQuery("select count(*) from P p where p.userID in (:userIDs)");
// myUserIDs is a collection or an Object[]
q.setParameterList("userIDs", myUserIDs);
count = ( (Integer) q.iterate().next() ).intValue();

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.