MySQL交叉连接查询中的Hibernate异常 [英] Hibernate Exception on MySQL Cross Join Query
问题描述
我试图执行一个对象Feature的批量删除,该对象与另一个类FeaturesMetadata具有Birdward ManyToOne关系。我有一个SQLGrammerException异常抛出。
我使用的hql:
String hql =从特征F中删除,其中F.featuresMetadata.stateGeoId =:stateGeoId;
打开显示SQL,会生成以下内容:
从FEATURE删除交叉连接FEATURESMETADATA featuresme1_,其中STATEGEOID =?
在db客户机中直接运行SQL会导致以下异常:
您的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以便在第1行的'交叉连接FEATURESMETADATA featuresme1_ where stategeoid = '01'附近使用正确的语法
由于生成的SQL抛出异常,我尝试将方言从MySQL5InnoDBDialect更改为MySQLInnoDBDialect,但没有更改。
任何人都可以帮助?
您可能没有加入这样的HQL查询。引用参考文档:
可以在批量HQL
查询中指定任何隐式或显式联接。子查询可以在where子句中使用,其中
子查询本身可以包含连接。
所以我想这样的东西应该工作:
pre $ 从特征F中删除F.id in
(从特征中选择f2.id f2 where f2.featuresMetadata.stateGeoId =:stateGeoId)
I'm trying to perform a bulk delete of an object, Feature, which has a birdirectional ManyToOne relationship with another class, FeaturesMetadata. I'm having a SQLGrammerException thrown.
The hql I'm using:
String hql = "delete from Feature F where F.featuresMetadata.stateGeoId = :stateGeoId";
Turning on show SQL, the following is generated:
delete from FEATURE cross join FEATURESMETADATA featuresme1_ where STATEGEOID=?
Running the SQL directly in the db client gives this exception:
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
Since the generated SQL is throwing the Exception, I tried changing dialects from MySQL5InnoDBDialect to MySQLInnoDBDialect, but no change.
Can anyone assist?
You may not have joins in such a HQL query. Quote from the reference documentation:
No joins, either implicit or explicit, can be specified in a bulk HQL query. Sub-queries can be used in the where-clause, where the subqueries themselves may contain joins.
So I guess something like this should work:
delete from Feature F where F.id in
(select f2.id from Feature f2 where f2.featuresMetadata.stateGeoId = :stateGeoId)
这篇关于MySQL交叉连接查询中的Hibernate异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!