我在使用hibernate进行对mysql的数据进行分页查询的时候,用到执行到query.setMaxResults()的时候,报错误
报错:
Hibernate: select top 4 goods0_.id as id5_, goods0_.supplierId as supplierId5_, goods0_.bigCategoryId as bigCateg3_5_, goods0_.smallCategoryId as smallCat4_5_, goods0_.goodsBianhao as goodsBia5_5_, goods0_.name as name5_, goods0_.synopsis as synopsis5_, goods0_.unitprice as unitprice5_, goods0_.brand as brand5_, goods0_.factoryProduction as factory10_5_, goods0_.purchasePrice as purchas11_5_, goods0_.chanpinxilie as chanpin12_5_, goods0_.chanpinleixing as chanpin13_5_, goods0_.gonglv as gonglv5_, goods0_.guigechicun as guigech15_5_, goods0_.yingyongkongjian as yingyon16_5_, goods0_.shiyongmianji as shiyong17_5_, goods0_.chanpinfengge as chanpin18_5_, goods0_.chanpingongneng as chanpin19_5_, goods0_.sewen as sewen5_, goods0_.xiansezhishu as xiansez21_5_, goods0_.caizhi as caizhi5_, goods0_.zhibao as zhibao5_ from ruilinxitong.goods goods0_ where 1=1 and goods0_.smallCategoryId=?
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.ruilin.dao.impl.GoodsDaoImpl.getAlumByGidAndTitle(GoodsDaoImpl.java:54)
at com.ruilin.dao.impl.GoodsDaoImpl.main(GoodsDaoImpl.java:86)
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 '4 goods0_.id as id5_, goods0_.supplierId as supplierId5_, goods0_.bigCategoryId ' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
... 9 more
现在该如何解决呀
很急的问题,帮忙解答,万分感谢