-->
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.  [ 4 posts ] 
Author Message
 Post subject: count query
PostPosted: Wed Nov 24, 2004 6:21 am 
Newbie

Joined: Sun Aug 29, 2004 11:45 am
Posts: 16
Hi,

What is the required syntaxt when using count queries when the gained query is from session.createSQLQuery?

Forom some reason it is not possible to call list()/ iterate() like in queries that were created throught session.createQuery()

thanks


Top
 Profile  
 
 Post subject: Re: count query
PostPosted: Wed Nov 24, 2004 11:13 am 
Newbie

Joined: Sun Nov 21, 2004 7:52 pm
Posts: 7
Location: Montr
You can try:

int numberOfHits =
((Integer)session.createQuery(query.toString()).uniqueResult()).intValue();

uniqueResult will return 0 if no match found or the number of records corresponding to your count request. With a count query UniqueResult never return null.

or you can try:

numberOfHits = ((Integer).iterate(query.toString()).next()).intValue();

Both ways works fine but i don't know wich is the best to use.

_________________
Hibernate user, trying to get the best of it.


Top
 Profile  
 
 Post subject: Re: count query
PostPosted: Wed Nov 24, 2004 11:17 am 
Newbie

Joined: Sun Nov 21, 2004 7:52 pm
Posts: 7
Location: Montr
ledome20 wrote:
You can try:

i forgot the word session in the second query

int numberOfHits =
((Integer)session.createQuery(query.toString()).uniqueResult()).intValue();

uniqueResult will return 0 if no match found or the number of records corresponding to your count request. With a count query UniqueResult never return null.

or you can try:

numberOfHits = ((Integer)session.iterate(query.toString()).next()).intValue();

Both ways works fine but i don't know wich is the best to use.

_________________
Hibernate user, trying to get the best of it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 12:54 pm 
Newbie

Joined: Sun Aug 29, 2004 11:45 am
Posts: 16
My problem is that I am not using createQuery but createSQLQuery so what you have suggested can not work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.