-->
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: count query result
PostPosted: Fri Apr 02, 2004 10:04 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
Hello,

How can I count the number of results of a query without returning the result values? (It would be difficult to create another query for counting because the queries are not created by me.)

SQL have the following:

select count(*) from (some subquery)
eg. select count(*) from (select * from countries)

but HQL doesn't allow me to write:

select count(*) from (from some.package.Country)


Thanks for any help,
Norbi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 11:03 am 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Norbi,

Try something like

Code:
List l = session.find("select count(obj) from com.foo.bar.Obj as obj");
Iterator it = l.iterator();
if (it.hasNext()) {
  Number n = (Number)it.next();

  //do something with n.intValue()
}

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 11:14 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
Thanks for the reply, but I'd like to apply this "counter" on generic queries.

My concrete question is: how can I write a HQL query to express the following SQL:

select count(*) from (complex subquery)

Because HQL does not allow this with this syntax.

Thanks,
Norbi


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.