-->
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.  [ 7 posts ] 
Author Message
 Post subject: Retrieving large result sets in pieces
PostPosted: Thu Jan 13, 2005 3:34 pm 
Newbie

Joined: Thu Jan 06, 2005 4:25 pm
Posts: 12
Location: Redwood City, CA
Hi,

I'm in a situation where I'd like the user of a web application to be able to page through a long list of entities. What's the recommended way to handle this in Hibernate?

I looked at the ScrollableResults object but it's not clear to me whether this object can be stored and reused between sessions or not.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 3:57 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
I'm a fan of using lazy collections with my application, that way my UI component (In my case, a Tapestry table grid that handles paging automatically) can just re-query each time the page is displayed. Only the records displayed are actually loaded.

This approach only works well if the display set is small (say 25 or less) because each row displayed results in a trip back to the DB (unless the objects are cached). The single query to fetch the collection is fast because only ID's and Version numbers are involved. Note: You can't return lazy results from HQL - you have to use the Criteria API. (Which sucks, in my opinion! Hoping for this feature in H3.) A child collection can simply be mapped as lazy="true",

Another approach is to use a Query object and page through your results one at a time. You can do this using: Query.setMaxResults() and Query.setFirstResult(). The problem here is that you still have to run the query each time, but it limits the results. BTW, this is covered in the FAQ, which is worth reading and will allow you to take off your asbestos underwear when posting to this forum.

There are probably other approaches, but these have worked well for me.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 4:02 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://blog.hibernate.org/cgi-bin/blosx ... find&path=

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 4:12 pm 
Newbie

Joined: Thu Jan 06, 2005 4:25 pm
Posts: 12
Location: Redwood City, CA
Thanks for the reply. I like the idea of using setFirstResult and setMaxResults. As an old JDBC hand, I'm wondering how these are implemented; I'm thinking probably a scrollable result set? Any idea if it's reasonably efficient to retrieve, say, the middle 100 items in a list of several million?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 4:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
this is done with database-specific functions like "select first x start y ..."


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 4:24 pm 
Newbie

Joined: Thu Jan 06, 2005 4:25 pm
Posts: 12
Location: Redwood City, CA
I'm using Oracle 8, I don't think it supports any keywords like FIRST or START. How do you handle it in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 5:24 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
test and read generated sql

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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