-->
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: Paging query returns different results depending on database
PostPosted: Thu Feb 10, 2011 5:02 am 
Newbie

Joined: Wed Feb 02, 2011 12:31 pm
Posts: 3
Location: München, Germany
Hi,
I want to get a (paginated) list of account numbers from a temporary report table that contains a list of deals. A row has got reportid, a deal, and an account:

Code:
CREATE TABLE REPORT ( REPORTID  INTEGER, DEAL INTEGER, ACCOUNT VARCHAR(25))


I use the query:

Code:
SQLQuery query = session.createSQLQuery("select distinct ACCOUNT from REPORT where REPORTID  = ? ORDER BY ACCOUNT  ");
[b]query.setFirstResult(startRow);[/b]
if (blockSize > 0) {
   [b]query.setMaxResults(blockSize);[/b]
}
List<String> accounts = query.list();



The problem ist: depending on the database the accounts list object does NOT contain only strings.
With Oracle 10g the list contains a list af arrays; every array has a length of 2 with object[0] : ACCOUNTNO, object[1]: Row-Number (BigDecimal)

For Oracle Hibernate performs a query like this:

Code:
select * from ( select row_.*, rownum rownum_ from ( select distinct ACCOUNT from REPORT where REPORTID = ? ORDER BY ACCOUNT ) row_ where rownum <= ?) where rownum_ > ?


With DB2 the query generated by Hibernate is even different: the order of ACCOUNT and row number is different: the row number comes first and is a BigInteger.

Trying all this with H2 everything is as expected.

Is there any solution to handle these database specific problems?

Do I have to write database specific code for inspecting the query results?


I cannot believe...
Please help. Thanks!


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.