-->
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: Performance & count
PostPosted: Wed May 05, 2004 11:07 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
Hi!
Just a question about performance (Hibernate 2.1.3 & MySQL 4.0.18): i need to retrive objects with Criteria+Example.
I must put the result on different pages with "prev" and "next" and for this purpouse i use criteria.setFirstResult and setMaxResults.
But, i need to know how many objects there are that match the Criteria+Example. I use "criteria.list().size()" but it's very expensive because it make a select over all the records (not paged).
There is a less expensive way?! Remember that i must use Criteria so i think I can't use "count(..)"...

The code:
Code:
int count=criteria.list().size();

if(count>0) {
  criteria.setFirstResult(firstResult);
  criteria.setMaxResults(maxResult);
  listComuni=criteria.list();
}


Maybe a better (not the best) solution is to create a Filter from the first criteria.list() and then setFirst and setMax on that!

Gio


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 11:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Unfortunately there is yet no better way - There are existing feature requests to add a method to do .count on the Criteria API, however we are still pondering about the best way to structure the API to do this.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 11:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Btw, doing another criteria.list with setMaxResults/setFirstResult afterwards is completely useless, you have already retrieved all data. So the best thing currently doable would be to just do a .list and select the data you need from the result.


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.