hibernate自带HQL一般只用于查询语句;
而增删改需要在query执行之后再调用query.executeUpdate();
但是经测试后一直报异常如下:
[color=red] org.hibernate.QueryException: query must begin with SELECT or FROM: delete[/color]
经过网上查询其原因是:
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> 即可!
而增删改需要在query执行之后再调用query.executeUpdate();
但是经测试后一直报异常如下:
[color=red] org.hibernate.QueryException: query must begin with SELECT or FROM: delete[/color]
经过网上查询其原因是:
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> 即可!