Hi everybody.
I use hibernate 3 with HSQL in Spring 2.5
I'm trying to use pagination by doing this :
Code:
Query query = session.createQuery("from Event");
query.setFirstResult(pageSize * pageNumber);
query.setMaxResults(pageSize);
return query.list();
If pageSize is different from 0, I obtain :
Code:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select event0_.ID as ID0_, event0_.TITLE as TITLE0_, event0_.URL_TITLE as URL3_0_, event0_.DESCRIPTION as DESCRIPT4_0_, event0_.CREATION_DATE as CREATION5_0_, event0_.LAST_UPDATE as LAST6_0_, event0_.START_DATE as START7_0_, event0_.END_DATE as END8_0_, event0_.IS_CHARGED as IS9_0_, event0_.IS_PRIVATE as IS10_0_, event0_.PICTURE as PICTURE0_, event0_.PLACE as PLACE0_ from EVENT event0_ order by event0_.CREATION_DATE DESC];
nested exception is java.sql.SQLException: Unexpected token: , in statement [select event0_.ID as ID0_, event0_.TITLE as TITLE0_, event0_.URL_TITLE as URL3_0_, event0_.DESCRIPTION as DESCRIPT4_0_, event0_.CREATION_DATE as CREATION5_0_, event0_.LAST_UPDATE as LAST6_0_, event0_.START_DATE as START7_0_, event0_.END_DATE as END8_0_, event0_.IS_CHARGED as IS9_0_, event0_.IS_PRIVATE as IS10_0_, event0_.PICTURE as PICTURE0_, event0_.PLACE as PLACE0_ from EVENT event0_ order by event0_.CREATION_DATE DESC limit ?, ?]
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:111)
If I take setFirstResult or set MaxResult of my code, there is no error anymore. So it has to be setFirstResult() or setMaxResult, not both at the same time. Or if i do firstResult( 0) and use setMaxResult(pageSize) it will be ok.
Any idea ? I'm stuck right now with that problem. The SQL query looks OK to me :(
Thanks a lot