2010-11-30 2 views
1

J'ai fait des critères, mais quand j'utilise setMaxResults, il me donnera une exception SQLGrammarException. Mais quand je commente setMaxResults, cela retournera toutes les entrées après le premier résultat. J'utilise la base de données MySQL.Hibernate en utilisant les critères setMaxResults donnant SQLGrammarException

code:

return criteria 
      .setFirstResult(start) 
      .setMaxResults(end) 
      .setFetchSize(end) 
      .list(); 

Exception:

org.hibernate.exception.SQLGrammarException: could not execute query 
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) 
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
    at org.hibernate.loader.Loader.doList(Loader.java:2536) 
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) 
    at org.hibernate.loader.Loader.list(Loader.java:2271) 
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) 
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716) 
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) 

.... 

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ... 
+2

Essayez de régler la « propriété show_sql' true et vérifier la requête générée essayer figureout problème il –

Répondre

4

problème est maintenant résolu. J'ai eu un mauvais dialecte dans les propriétés d'hibernation. J'avais copié mes propriétés d'un autre projet qui utilisait SQL Server, mais celui-ci utilise MySQL, donc un mauvais dialecte était à l'origine de cette erreur.

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect 
+0

je suis arrivé erreur quand j'utilisais cette propriété: , mais quand je l'enlève, ça fonctionne très bien. merci newbie :) – Hazim

Questions connexes