-->
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: DetachedCriteria : count before limitation?
PostPosted: Mon Aug 16, 2010 4:55 am 
Newbie

Joined: Mon Aug 16, 2010 4:47 am
Posts: 4
Hello,

Maybe my question is stupid but I'm wondering the following thing :

If I want to limit my search results (for instance I just want the 50 first records) by using DetachedCriteria, I do :

Code:
List<Object> liste = getHibernateTemplate().findByCriteria(crit,0,50);


Everything is OK.

However, I would like to get the number total of records of the request without a COUNT before.

Clearly : just call one time findByCriteria and get the total size and my list (which is limited).

Is that possible?

Thanks in advance !


Top
 Profile  
 
 Post subject: Re: DetachedCriteria : count before limitation?
PostPosted: Mon Aug 16, 2010 5:07 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Fearless,

You may set the max results to be returned as 50. But it may not always cross 50 records it may also be less than 50. If you need only the count from the query, it is advisable to use count() instead returning all the results.

As you said, you can also go with the size of the list.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: DetachedCriteria : count before limitation?
PostPosted: Mon Aug 16, 2010 8:08 am 
Newbie

Joined: Thu Aug 12, 2010 3:07 pm
Posts: 3
Location: Madrid, Spain
Watch out at the moment of use Projections.rowCount(), I'm having troubles trying to get the total record count with a criterion already created.

https://forum.hibernate.org/viewtopic.php?f=1&t=1006434

_________________
I made a covenant with God, he doesn't develop software and I don't do miracles


Top
 Profile  
 
 Post subject: Re: DetachedCriteria : count before limitation?
PostPosted: Mon Aug 16, 2010 8:26 am 
Newbie

Joined: Mon Aug 16, 2010 4:47 am
Posts: 4
Shynate26 : you're right, but what I need is to know how many records are in my request.

Clearly : imagine I my request (with DetachedCriteria) contains 60 results and I just want the 50 first.

I do : findByCrit(crit,0,50), it's ok.

But I would like, in the same time, knowing that my request contains 60 results.

The solution is to do a COUNT but the request is heavy, I'm looking for an easier solution, maybe it doesn't exist !

Britanico : I'm gonna watch it, thanks.


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.