Hibernate version: 3.0.5
I tested a simple query with pagination on DB2 8.2. If there is no order, everything goes ok. But when I added order, Hibernate generated wrong sql. In the trace, I found that Hibernate used DB2's 'rownumber() over( ... ) ' to implement the pagination, but if there is 'order by', the DB2 dialect copy the 'order by ...' subclause to the 'over (... ) ' function, and then the problem happens, for that in over() function, DB2 does not allow column alias. For example , this sql is corret on DB2:
Code:
select column1 as c1, rownumber() over(column1) from table1 t1 order by t1.c1
while the following is not:
Code:
select column1 as c1, rownumber() over(c1) from table1 t1 order by t1.c1