-->
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.  [ 2 posts ] 
Author Message
 Post subject: select distinct limit query in DB2 (bug in DB2 dialect)
PostPosted: Wed Dec 01, 2004 12:53 am 
Newbie

Joined: Wed Dec 01, 2004 12:44 am
Posts: 3
When using limit queries with the DB2 dialect, the SQL generated looks something like this:

select * from ( select distinct rownumber() over ( ) as row_ from $fromClause where $whereClause ) where row_ between...

this unfortunately does not produce the desired result, as the inclusion of the rownumber() function in the result set makes every row distinct anyway.

Proposed fix for the DB2Dialect:

Code:
   public String getLimitString(String sql, boolean hasOffset)
   {
      StringBuffer pagingSelect = new StringBuffer(sql.length() + 100).append(
            "select * from(select temp_.*, rownumber()over(order by 1)as row_ from(")
            .append(sql)
            .append(" ) as temp_) as temp2_ where row_ ");
      if (hasOffset)
      {
         pagingSelect.append("between ?+1 and ?");
      } else
      {
         pagingSelect.append("<= ?");
      }
      return pagingSelect.toString();
   }


which will generate select * from ( select *, rownumber() over () as row_ from (select distinct $selectClause FROM $fromClause WHERE $whereclause)...).

This uses an additional subselect, however.

Max

Hibernate version: 2.1.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I'd say file a JIRA enty with a patch attatched in patch format


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