I'm a newbie and trying to fetch records in a Springboot application from DB2 database with paging concept.
The service call works great when I set offset=0 and size = 'n'
But when I set the offset to anything else, be it 1 or 2 or any the service fails and returns the following: (I'm unable to give the entire log because of restrictions, so please bear with it)
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
There is also an exception thrown by the SQL Driver as follows:
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=OF;ROWS * AT YEAR YEARS MONTH MONTHS DAY DAYS HOUR HOURS MINUTE, DRIVER=4.21.29
Hibernate is generating the following SQL query for offset=1, size=2 (in page fetch)
SELECT * FROM (SELECT inner2_.*, rownumber() over (order by order of inner2_) as rownumber_ from (select fields from table_name fetch first rows only) as inner2_) as inner1_ where rownumber_ > <offset*size> order by rownumber_
The bold marked text is the actual query syntax, whatever is left out of bold is the field names (that cannot be publicly exposed), please substitute offset and size values as stated.
FYI: My API service call returns Page <T>
as follows
Repository.findAll(PageRequest.of(offset, size)); (Repository extends JpaRepository)