-->
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.  [ 5 posts ] 
Author Message
 Post subject: hibernate pagination
PostPosted: Thu Oct 26, 2006 3:09 pm 
Newbie

Joined: Wed Mar 15, 2006 10:56 am
Posts: 8
Location: Ohio USA
Hi all,

This might sound crazy but I need some inputs on the hibernate pagination.
I presume that by using the methods

sqlquery.setMaxResults
sqlquery.setFirstResult

we can achive pagination. But the question remains is that these methods will take into effect after the ResultSet is fetched from the database. Corerct me if I am wrong.

This means that the query might be fetching 10,000 records but these filters will be applied upon these 10,000 records and then a small subset will be returned back to the user.

Is there any way that we can fetch only limited number of records and achieve maximum response time?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If you read the source for the database dialects you will see these otpions modify the generated SQL to limit the SQL resultset generated as much as possible. Alternatively, if the JDBC driver is well writen you could use a scroll ing resultset.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:46 pm 
Newbie

Joined: Wed Mar 15, 2006 10:56 am
Posts: 8
Location: Ohio USA
David,

Could you eloborate on this.

This is what I do for my pagination.

Session session = getSession();
session.getTransaction().begin();
sqlquery = session.createSQLQuery(s);
sqlquery.setMaxResults(100);
sqlquery.setFirstResult(0)// this will vary as you page by
return sqlquery.list();

What I found is this results in the database query to be fired with all the results got into the ResultSet and then these are applied and I get a sublist out of this.

My question is can I ensure that instead of hibernate getting all 1000 records and returning back only 100, can i execute only 100 and return back that 100 alone.

Thsi was I can ensure that my responses are pretty much faster


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 4:13 pm 
Newbie

Joined: Wed Jan 10, 2007 5:20 pm
Posts: 8
does anyone has an idea, I have the same issue,

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 6:20 pm 
Newbie

Joined: Fri May 25, 2007 6:19 pm
Posts: 2
We had the same problem for a while; it turned out that our DB "dialect" was not set exactly right. So check that. I assume your DB actually does support "top" or other similar syntax.


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