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