public List getquery() throws Exception
{

Session session = super.getSession();

List list = null;
Query query = session.createQuery(" from User ");
query.setFirstResult(1*3);
query.setMaxResults(3);
list = query.list();
session.close();
return list;

}运行后报错
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.yangtianb.dao.UserInfoDAO.getquery(UserInfoDAO.java:46)
at com.yangtianb.web.Test.main(Test.java:11)
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 '() as rownumber_, user0_.id as id0_, user0_.name as name0_ from user user0_ ) as' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

解决方案 »

  1.   

    sql 语法错误
    我看你代码里面也没有什么问题
    你检查下 User 的hibernite的配置文件是否有问题
      

  2.   

    在这里建议阁下不要用Hibnate自带的换行。如果能够配置的非常好那还不错。建议还是写存储过程。这样可以减轻数据库的负担。
      

  3.   


    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 '() as rownumber_, user0_.id as id0_, user0_.name as name0_ from user user0_ ) as' at line 1
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    这句话什么意思啊?
      

  4.   

    语法错误,把你Sql前后的空格都去掉试试!
    Query query = session.createQuery("from User");
      

  5.   

    打印出sql语句,复制到数据库执行下,看哪里出错,然后根据位置修改程序
      

  6.   

    showsql设置为true 看看是不是方言的问题 不用分页就不会出错还是说之前也用了分页 到现在才出的错?
      

  7.   

    找到问题了,hibernate.cfg.xml中数据库方言用错了<property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    应该用MYSQL的,我用成了DB2的了。
    但为什么方言用错了,对有些操作不会造成影响呢?比如我查询一个表的总条数,就能查出来··
      

  8.   


    有些语句是通用 但是MYSQL的分页语句跟DB2肯定不一样啊 MYSQL是用limit分页 DB2也许有其他的函数吧
    恩恩 方言问题~