-->
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.  [ 6 posts ] 
Author Message
 Post subject: Entitymanager Paging
PostPosted: Wed Jun 11, 2008 9:55 am 
Beginner
Beginner

Joined: Sat Oct 20, 2007 8:28 am
Posts: 28
Hi ,
i've searched the forum but couldn't find any refrence to it .
as i udnerstand when using the paging mechanism of :
q = em.cretequerry
q.setmax
q.setfrstrslt

and using this mechanism for paging (from the documents i understand this is the way E.M is supposed to implement paging) i've noticed hibernate selects the entire results using TOP before up untill the last one it needs and itterates over them in memory ?? this seems to be very memory inefficent .
i've tried to implment it using ROW_NUMBER() but it's not as "pretty" , is there a better way to utilize the paging mechanisim and not load such a big bulk into memory when all u need is 50 rows (i have tables of thousands of rows and i only need 50 at a time and it's very likely user will sort on a single column and jump to page 56 ?
the question is asked using sql server syntax but i want to stay db independent .


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 4:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

the syntax is something along this lines (from the documentation):

Code:
Query q = sess.createQuery("from DomesticCat cat");
q.setFirstResult(20);
q.setMaxResults(10);
List cats = q.list();


Note that there is no standard way in SQL to express pagination. Hibernate tries to use the appropriate queries depending on the db. I am not sure how this looks like for SQLServer.

Why do you think that all rows up to 'maxresult - 1' get selected?

--hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 1:14 pm 
Beginner
Beginner

Joined: Fri Jun 15, 2007 6:32 am
Posts: 23
hardy.ferentschik wrote:
Hi,

the syntax is something along this lines (from the documentation):

Code:
Query q = sess.createQuery("from DomesticCat cat");
q.setFirstResult(20);
q.setMaxResults(10);
List cats = q.list();


Note that there is no standard way in SQL to express pagination. Hibernate tries to use the appropriate queries depending on the db. I am not sure how this looks like for SQLServer.

Why do you think that all rows up to 'maxresult - 1' get selected?

--hardy


there's no cross db way to do it but it seems it's an important enough requirment to be delt in each db optimaly .
i'm printing the queries and debugging and from what i've seen a on sql server it uses a top query with maxresult+firstresult and itterates over the previous records .


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 4:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi again,

I checked the code for the SQLServer dialect and as you say it is just limiting the query with TOP. SQLServer does not support a limit functionality. If you would switch to another database which supports it (PostgreSQL, MySQL, Oracle, ...) you would get the expected results.

How would your approach with ROW_NUMBER() look like? Note though that ROW_NUMBER() is a function new in SQLServer 2005. Currently there is only one single SQLServerDialect in Hibernate. If your approach is feasible one would have to split the dialects in order to integrate this approach. Maybe you want to continue this discussion on the Hibernate Core forum since it is not entity manager related?

Last but not least you could look into using scrollable resultsets. Have a look at these wiki pages:
- http://www.hibernate.org/314.html
- http://www.hibernate.org/248.html

If you are using the jTDS driver for SQLServer you might get a real performance boost.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 3:55 am 
Beginner
Beginner

Joined: Sat Oct 20, 2007 8:28 am
Posts: 28
i've handled this issue before with hibernate specific solution like you suggested and they work very good but now i'm trying to stay vendor independent and not ask for the delegate .
this is why i asked it in E.M forum .


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 4:23 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
i've handled this issue before with hibernate specific solution

I've had the same problem, unfortunately with SQL server 2000 (not-negotiable client requirement), and we couldn't find something better that using scrollables, and/or Lucene by using Search (depending on the kind of search).

How did you handle this before?
Are cursors mandatory?
Do you think it is possible to achieve on sql server 2000 too?

_________________
Sanne
http://in.relation.to/


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