gpt4 book ai didi

java - 使用连接或嵌套子查询更新 Hibernate (HQL)

转载 作者:行者123 更新时间:2023-11-29 08:50:49 27 4
gpt4 key购买 nike

我在创建使用嵌套查询或使用连接更新实体 CommitteeMembership 的 HQL 时遇到问题,我首先尝试了这个查询:

update CommitteeMemberShip cms set cms.isDeleted=1 
where cms.committeeCycle.committee.id=:committeeId

但是生成的SQL错误如下:

update CommitteeMemberShip cross join  set isDeleted=1 where committee_id=?

在“cross join”之后没有任何这个会使 Hibernate 抛出 SQLGrammarException

之后,我将查询更改为使用子查询:

update CommitteeMemberShip cms set cms.isDeleted=1 
where cms.id in (select cmsIn.id from CommitteeMemberShip cmsIn inner join
cmsIn.committeeCycle cc inner join cc.committee c where c.id=:committeeId)

现在 Hibernate 抛出

java.sql.SQLException: You can't specify target table 'CommitteeMemberShip' for 
update in FROM clause

有人知道我如何用 HQL 编写这个更新查询吗??

最佳答案

试试这个

更新 CommitteeMemberShip cms set cms.isDeleted=1where cms.id = some(select cmsIn.id from CommitteeMemberShip cmsIn inner joincmsIn.committeeCycle cc inner join cc.committee c where c.id=:committeeId)

关于java - 使用连接或嵌套子查询更新 Hibernate (HQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22787137/

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