-->
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: setFirstResult and setMaxResult -> Bad SQL grammar
PostPosted: Thu Nov 27, 2008 5:15 pm 
Newbie

Joined: Tue Oct 28, 2008 5:27 pm
Posts: 4
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


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.