-->
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.  [ 2 posts ] 
Author Message
 Post subject: a problem about hibernate Paging
PostPosted: Mon Aug 15, 2005 10:16 pm 
Beginner
Beginner

Joined: Thu Jul 07, 2005 5:17 am
Posts: 30
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 ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 11:20 am 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
You have two different queries that you are explicity asking Hibernate to execute. If you want to improve the performance of your first query use a count(*) instead of fetching your entire table into memory.


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