【发布时间】:2014-05-12 07:13:27
【问题描述】:
我在创建使用嵌套查询或使用联接更新实体 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=?
在“交叉连接”之后没有任何 this 会使 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)
现在休眠抛出
java.sql.SQLException: You can't specify target table 'CommitteeMemberShip' for
update in FROM clause
任何人都知道如何在 HQL 中编写此更新查询??
【问题讨论】: