-->
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.  [ 1 post ] 
Author Message
 Post subject: Pagination on an Oracle Database
PostPosted: Tue Nov 23, 2010 3:19 pm 
Newbie

Joined: Fri Mar 21, 2008 6:02 pm
Posts: 1
Sorry if this had been brought up before.. I did some Google Searches and just didn't find anything (maybe I didn't use the right search terms). Regardless, I had the following issue this morning. When I was trying to do Pagination on an Oracle database the following was my code:

Code:
        criteria = session.createCriteria(object.getClass());
        criteria.setFirstResult(start);
        criteria.setMaxResults(maxResults);
        returnList = criteria.list();


This produces (shortened) SQL similar to the following (INVOICE_PUBS is obviously my table):

Code:
select * from ( select row_.*, rownum rownum_ from ( select * from INVOICE_PUBS this_ ) row_ ) where rownum_ <= 35 and rownum_ > 30


This worked on one database and not on another. I have no idea why it worked on the one database because it shouldn't have. You MUST put an Order clause in the criteria for the pagination to work properly:

Code:
        criteria.addOrder(Order.asc("theId"));


This will correctly produce the following SQL with the Order By clause

Code:
select * from ( select row_.*, rownum rownum_ from ( select * from INVOICE_PUBS this_ order by this_.INVC_PUBS_ID asc ) row_ where rownum <= 35) where rownum_ > 30


My recommendation would be that if there isn't an "Order By" clause already in the criteria that Hibernate use the "id" (it should know what the Id is I'd think).

Anyway, this tied up my morning and with the help of my DBA was able to resolve the issue.

Thomas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.