我有嵌套查詢創建HQL的更新實體CommitteeMembership或使用加入一個問題,我第一次嘗試這樣的查詢:更新使用連接或nasted子查詢的Hibernate(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=?
沒有任何在此之後「交叉聯接」使休眠拋出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此更新查詢?
我認爲這將做到第二次嘗試的子查詢有問題,它拋出s: java.sql.SQLException:您無法在FROM子句中指定目標表'CommitteeMemberShip'進行更新 –
我不確定,但試試這個 更新CommitteeMemberShip cms加入cms.id = cms2.id設置cms的CommitteeMemberShip cms2。 isDeleted = 1 其中cms2.committeeCycle.committee.id =:committeeId – Fanooos
您不能在實體名稱或別名後面寫入連接,它會拋出org.hibernate.hql.ast.QuerySyntaxException:期待「設置」,找到「連接」 –