-->
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.  [ 4 posts ] 
Author Message
 Post subject: Paging strategies - performance
PostPosted: Mon Jun 06, 2005 9:49 am 
Newbie

Joined: Mon Jun 06, 2005 9:03 am
Posts: 2
Hi i read some posts & articles and still i cant find the best approach in paging with hibernate.(or I found one but i cant find why)

Lets consider example (common) problem:

In web appication user have form where can specify few query criteria , after search hi recives a search results paginated in to few pages (search result are large).

The best strategy i found is described below : (setMaxResults & setFirstResult):

1)Atter user submit first form , some servlet builds the query and sets the result size via setMaxResults and setFirstResult. After response from DB forward to result form. When user change actual page in result form is redirected to first servlet.

This approach have few disadventages (in my opinnion):
Every time user changes page the query.list() is executed so DB have to parse, optimalize and evaluate query.

I was wandering if it is better way to solve this problem.
I found one but i dont know if it is better - plese read and comment.

2)Afther user submit first form servlet 'A' create the query and send it to DB but dont retrive any row (session.scroll()). Then other servlet 'B' retrives ScrollableResult (from session, context..) and call:
-scroll.first()
-scroll.scroll(PAGE_NUM * PAGE_SIZE)
-retrive PAGE_SIZE elements and add to some collection witch is displayed in results form.
When user changes page is redirected to servlet 'B' - work done by servlet 'A' isnt done again.

Adventage in this approach is that servlet 'A' is executed only once (ather submitting criteria form), and then n times is executed servlet 'B' ( n - number of swithcing pages).
I really dont know if it is :
a)faster : what is fatser scroll(PAGE_NUM * PAGE_SIZE) then setMaxResults ,setFirstResult , query.list()

b)safer: how its behave when during switching pages some other user delete or create few rows.

Im waiting for comments.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 9:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Do not EVER hold a ResultSet open across a user interataction. This is basic rules of JDBC scalability.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 10:05 am 
Newbie

Joined: Mon Jun 06, 2005 9:03 am
Posts: 2
Sorry for stupid question: WHY ?
If u have any links where i can read about it please post it here.
Thx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 10:15 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is this ting some people use, its apparently quite good for searching for information: http://www.google.com And there is even a l33t version for kids!


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