Hi,
I want get the sum number of the resultSet before paging,I write the code:
Query query = session.createQuery("from resource i");
int sumSize=query.list().size();
System.out.println("sum size is "+sumSize);
query.setFirstResult(0);
query.setMaxResults(5);
list = query.list();
int pageSize=list.size();
System.out.println("page size is "+pageSize);
hibernate will execute the 'select' SQL 2 times:
Hibernate: select resource0_.RSBIRID as RSBIRID, resource0_.RSBICatId as RSBICatId, resource0_.RSBIISBN as RSBIISBN from Resource resource0_
sum size is 998
Hibernate: select resource0_.RSBIRID as RSBIRID, resource0_.RSBICatId as RSBICatId, resource0_.RSBIISBN as RSBIISBN from Resource resource0_
page size is 5
how can i modify the code and make hibernate execute only one time ?
|