Hibernate常见问题

1) 当用myeclipse生成对象的xml时,如果用classes12.jar包的话可以生成带注释的XML文件。

2)   Query q = session.createQuery("from Chat order by id desc");
        q.setFirstResult(0);
        q.setMaxResults(10);
        报错:com.mysql.jdbc.exceptions.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 '10 chat0_.id as id0_, chat0_.username as username0_, chat0_.message as message0_' at line 1

       查找好久没有找到原因,后看后台打印语句,发现为:

 

 select top 11 chat0_.id as id0_, chat0_.username as username0_, chat0_.message as message0_,
chat0_.time as time0_
from test.chat chat0_
order by chat0_.id desc

 

       因为我的数据库为mysql,而mysql选取部分结果集应为limit 0,10这样,查看Hibernate方言后发现用的是sqlserver方言,故改成mysql后成功!

你可能感兴趣的:(Hibernate)