gpt4 book ai didi

hibernate - 删除带有相关实体的 JPA2 中的查询

转载 作者:行者123 更新时间:2023-12-04 06:18:20 24 4
gpt4 key购买 nike

我正在尝试进行批量删除

@NamedQuery(name=CalcData.DELETE, 
query="delete from CalcData as model where model.dataLocation.locCountries = :locCountries and model.locPeriod= :locPeriod")

问题是 hibernate 将其转换为
Hibernate: 
delete
from
smart_rise.Calc_Data cross
join
smart_rise.Data_Location datalocati1_
where
CountryID=?
and Period=?

这在执行na​​medquery时会导致异常
=== 2011-08-04 10:53:30,719 [l0-6] ERROR JDBCExceptionReporter - 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 smart_rise.Data_Location datalocati1_ where CountryID=6 and Period=10' at line 1
=== 2011-08-04 10:53:30,719 [l0-6] ERROR PeriodsDMI - org.hibernate.exception.SQLGrammarException: could not execute update query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)

知道出了什么问题吗?

谢谢你,
兹达里

最佳答案

您不能使用联接删除。

locCountries是一个索引集合尝试子查询:

delete from CalcData as model 
where :locCountries in indicies(model.dataLocation.locCountries)
and model.locPeriod= :locPeriod

如果不:
delete from CalcData as model 
where model.id not in (select id from CalcData as m where model.dataLocation.locCountries = :locCountries and model.locPeriod= :locPeriod
)

问候。

关于hibernate - 删除带有相关实体的 JPA2 中的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6938693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com