http://k0441258778983.iteye.com/blog/1042580
hibernate自带HQL一般只用于查询语句;
而增删改需要在query执行之后再调用query.executeUpdate();
但是经测试后一直报异常如下:
org.hibernate.QueryException: query must begin with SELECT or FROM: delete
经过网上查询其原因是:
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> 即可!
-------------------------------------------------------------------------------------------------------------------
我是spring集合hibernate,现在修改applicationContext.xml中的属性为org.hibernate.hql.ast.ASTQueryTranslatorFactory 后删除正常
本文介绍了解决Hibernate使用HQL进行删除操作时出现的异常问题。通过更改hibernate.cfg.xml配置文件中的hibernate.query.factory_class属性值,从经典查询转换器改为AST查询转换器,成功解决了“querymustbeginwithSELECTorFROM”的错误。
4054

被折叠的 条评论
为什么被折叠?



