• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting large result sets using hibernate

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to get data from a large table. So I want to get it in segments, like ten rows at a time, so I don't blow up the memory. Is there a way I can do this with hibernate?

I might have to write some HQL or a stored procedure, which is ok, I am just not sure what the syntax would be.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4031
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to object relational mapping forum...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find the Hibernate Criteria API makes this very easy to do:



These two lines of code help to limit your results. Just use a counter, and you can easily allow clients to page through your results.


criteria.setFirstResult(0);
criteria.setMaxResults(5);

Tutorial on Using the Criteria API from Hibernate

-Cameron McKenzie
 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that works. Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one thing that I would add, is for me the Criteria object just for pagination is not using the Criteria object wisely. I prefer HQL for this kind of work. The Criteria I find better for simpler queries and also for those Example queries and ad hoc queries based on Search screens.

Mark
 
santhosh john
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an example for toplink here.traversing large result sets
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic