开发者

Hibernate using Criteria setMaxResults giving SQLGrammarException

I have made criteria, but when I use setMaxResults, it will give me exception SQLGrammarException. But when I comment setMaxResults, it will work an return all entries after first result. I'm using MySQL database.

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 o开发者_StackOverflow社区rg.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 ...


Problem is now solved. I had wrong dialect in hibernate properties. I had copied my properties from other project that used SQL Server, but this one uses MySQL, so wrong dialect was causing this error.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜