用Hibernate2实现分页,总是抛出异常,数据库用的是MySql 3.21,Server用的是Tomcat5,老是抛出异常Could not execute query!
//--------------------------------------
String hql = "from Article";
Session s = dao.getSession();
Query query = s.createQuery(hql);
query.setMaxResults(5);
query.setFirstResult(2);
List list = query.list();
//--------------------------------------net.sf.hibernate.exception.SQLGrammarException: Could not execute query
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:58)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at com.bitiliu.website.util.WebsiteBusiness.main(WebsiteBusiness.java:687)
Caused by: java.sql.SQLException: You have an error in your SQL syntax near 'select rownumber() over() as rownumber_, article0_.id as id, article0_.title as ' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2385)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2306)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1877)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1722)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
... 2 more