且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Hibernate之update(2)——报错query must begin with SELECT or FROM

更新时间:2022-08-15 09:34:27

 
hibernate自带HQL一般只用于查询语句,而增删改需要在query执行之后再调用query.executeUpdate();

但是经测试后一直报异常如下:
org.hibernate.QueryException: query must begin with SELECT or FROM:
 
原因:
hibernate 配置文件hibernate.cfg.xml里 解析hibernate 查询语言为2.X版本。

 解决办法:
<property name="hibernate.query.factory_class">
        org.hibernate.hql.classic.ClassicQueryTranslatorFactory </property>

将其改为3.X
<property name="hibernate.query.factory_class">
       org.hibernate.hql.ast.ASTQueryTranslatorFactory
</property> 
 
或者
 

2.x :hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory   

3.x:hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory 

 

原帖地址:http://k0441258778983.iteye.com/blog/1042580

参考地址:http://kangzye.blog.163.com/blog/static/3681922320098311461766/