-->
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: Pagination problem with DB2Dialect
PostPosted: Tue Jan 27, 2004 2:30 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
We are using Hibernate to handle pagination of a data set.

Query q = session.createQuery(query);
q.setMaxResults(maxRecordsPerPage);
q.setFirstResult(((pageNum - 1) * maxRecordsPerPage));


The paging is working correctly, except that it isn't ordering the results correctly. We have been troubleshooting this issue for about a day and a half and have tracked it down to a possible problem with the SQL that Hibernate is generating.

We gave the SQL that was generated to our DBA to look at and he came back with the following taken from the IBM DB2 manual.

Chapter 2 -> Expressions -> OLAP functions (Doc Page 210, PDF Page 234)

Quote:
The ROW_NUMBER (or ROWNUMBER) function computes the sequential
row number of the row within the window defined by the ordering, starting
with 1 for the first row. If the ORDER BY clause is not specified in the
window, the row numbers are assigned to the rows in arbitrary order, as
returned by the subselect (not according to any ORDER BY clause in the
select-statement).



Our DBA added the order by clause to the rownumber() over() function and it appeared to fix our problem.

(See the SQL below) Notice the second line....
rownumber() over()
changed to
rownumber() over(order by engagement0_.StartDate asc)


Any help on this issue would be greatly appreciated. Is there something that we are overlooking? Is this a DB2Dialect problem?

---------------------------------------------------------------------------

DATABASE
Version "DB2 v8.1.0.36", "s021023", "", and FixPak "0".

HIBERNATE DIALECT
net.sf.hibernate.dialect.DB2Dialect

OUR HQL
select e from com.matrix.bo.te.Engagement e where e.clientBill.client.id = 10

OUR METHOD THAT IS RETURNING THE LIST
Code:
public List findPageList(final String query, final int pageNum, final int maxRecordsPerPage) {

   return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session session) throws HibernateException, SQLException {

         Query q = session.createQuery(query);
         q.setMaxResults(maxRecordsPerPage);
         q.setFirstResult(((pageNum - 1) * maxRecordsPerPage));

         return q.list();
      }
   });

}   


HIBERNATE GENERATED SQL
Code:
select * from
      ( select rownumber() over() as row_,
              engagement0_.Engagement_ID as Engageme1_,
              engagement0_.ClientBill_ID as ClientBi2_,
              engagement0_.HiringMgr_ID as HiringMg3_,
              engagement0_.Consultant_ID as Consulta4_,
              engagement0_.ActEndDate as ActEndDate,
              engagement0_.CandIncType as CandIncT6_,
              engagement0_.CandType as CandType,
              engagement0_.EndDate as EndDate,
              engagement0_.EngageCode as EngageCode,
              engagement0_.ExpensesAllowed as Expense10_,
              engagement0_.EngagementName as Engagem11_,
              engagement0_.StartDate as StartDate,
              engagement0_.WebTimeSheets as WebTime13_,
              engagement0_.ajcEngagementName as ajcEnga14_,
              engagement0_.Engagement_ID as x0_0_,
              engagement0_.EngagementName as x1_0_,
              engagement0_.ajcEngagementName as x2_0_,
              engagement0_.StartDate as x3_0_,
              engagement0_.EndDate as x4_0_
        from DB2ADMIN.Engagement engagement0_,
             DB2ADMIN.ClientBill clientbill1_
        where (clientbill1_.Client_ID=10
        and engagement0_.ClientBill_ID=clientbill1_.ClientBill_ID)
        order by  engagement0_.StartDate asc ) as temp_
    where row_ between 30+1 and 60



THE SAME SQL SLIGHTLY MODIFIED BY OUR DBA
Notice the second line....
rownumber() over()
changed to
rownumber() over(order by engagement0_.StartDate asc)

Code:
select * from
          ( select rownumber() over(order by engagement0_.StartDate asc) as row_,
                  engagement0_.Engagement_ID as Engageme1_,
                  engagement0_.ClientBill_ID as ClientBi2_,
                  engagement0_.HiringMgr_ID as HiringMg3_,
                  engagement0_.Consultant_ID as Consulta4_,
                  engagement0_.ActEndDate as ActEndDate,
                  engagement0_.CandIncType as CandIncT6_,
                  engagement0_.CandType as CandType,
                  engagement0_.EndDate as EndDate,
                  engagement0_.EngageCode as EngageCode,
                  engagement0_.ExpensesAllowed as Expense10_,
                  engagement0_.EngagementName as Engagem11_,
                  engagement0_.StartDate as StartDate,
                  engagement0_.WebTimeSheets as WebTime13_,
                  engagement0_.ajcEngagementName as ajcEnga14_,
                  engagement0_.Engagement_ID as x0_0_,
                  engagement0_.EngagementName as x1_0_,
                  engagement0_.ajcEngagementName as x2_0_,
                  engagement0_.StartDate as x3_0_,
                  engagement0_.EndDate as x4_0_
            from DB2ADMIN.Engagement engagement0_,
                 DB2ADMIN.ClientBill clientbill1_
            where (clientbill1_.Client_ID=10
            and engagement0_.ClientBill_ID=clientbill1_.ClientBill_ID)
            order by  engagement0_.StartDate asc ) as temp_
    where row_ between 30+1 and 60
[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you submit it to JIRA, please

_________________
Emmanuel


Top
 Profile  
 
 Post subject: JIRA
PostPosted: Tue Jan 27, 2004 3:17 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
This has been submitted to JIRA


Top
 Profile  
 
 Post subject: JIRA
PostPosted: Tue Jan 27, 2004 3:20 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
Here is a link to the JIRA post....

http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HBI-21


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 4:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ooops! Thanks for noticing this. (Is it just me, or is that some rather bizarre behavior on the part of DB2?)

Would you please submit this to JIRA, since I might not get a chance to fix it today. This should be extremely easy to fix.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 5:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummm ... i typed this last post an hour ago and didn't submit it. Stupid me.


Top
 Profile  
 
 Post subject: But the problem i still met at hibernate 2.1.8!why?
PostPosted: Tue Apr 12, 2005 10:42 am 
Newbie

Joined: Sun Apr 10, 2005 4:36 am
Posts: 3
the problem still apear at my application.


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.