我正在尝试对对象Feature进行批量删除,该对象与另一个类FeatureMetadata具有双向ManyToOne关系。我正在抛出SQLGrammerException。

我正在使用的hql:

String hql = "delete from Feature F where F.featuresMetadata.stateGeoId = :stateGeoId";

打开show SQL,将生成以下内容:
 delete from FEATURE cross join FEATURESMETADATA featuresme1_ where STATEGEOID=?

直接在数据库客户端中运行SQL会出现以下异常:
 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 'cross join FEATURESMETADATA featuresme1_ where stategeoid='01'' at line 1

由于生成的SQL引发Exception,因此我尝试将方言从MySQL5InnoDBDialect更改为MySQLInnoDBDialect,但没有更改。

有人可以协助吗?

最佳答案

您可能没有这样的HQL查询中的联接。引用reference documentation:



所以我想这样的事情应该起作用:

delete from Feature F where F.id in
    (select f2.id from Feature f2 where f2.featuresMetadata.stateGeoId = :stateGeoId)

09-30 21:15