休眠、MySQL

发布于 2024-10-19 17:57:14 字数 503 浏览 2 评论 0原文

我有以下 hql 查询:

UPDATE TaskAssessment taskAssessment 
SET taskAssessment.activeFlag = false 
WHERE taskAssessment IN 
(
SELECT taskAssessment2 
FROM TaskAssessment taskAssessment2 
Where taskAssessment2.activeFlag = true 
AND taskAssessment2.patient.id 
AND taskAssessment2.needsLevel.careNeed = :careNeed
)

但它给了我错误:

You can't specify target table 'TASK_ASSESSMENT' for update in FROM clause

任何人都可以帮助我纠正 mysql 和 hibernate 的查询。提前致谢。

i have the following hql query:

UPDATE TaskAssessment taskAssessment 
SET taskAssessment.activeFlag = false 
WHERE taskAssessment IN 
(
SELECT taskAssessment2 
FROM TaskAssessment taskAssessment2 
Where taskAssessment2.activeFlag = true 
AND taskAssessment2.patient.id 
AND taskAssessment2.needsLevel.careNeed = :careNeed
)

but its giving me errors:

You can't specify target table 'TASK_ASSESSMENT' for update in FROM clause

could anyone help me to correct the query for mysql and hibernate. thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

季末如歌 2024-10-26 17:57:14

要解决您无法在 FROM 子句中指定要更新的目标表“TASK_ASSESSMENT”,请重写查询以使用 JOIN 而不是 IN(在mysql 你需要写这样的东西):

UPDATE TaskAssessment a
INNER JOIN TaskAssessment a2 ON (a2.id = a.id)
SET a.activeFlag = 0  
WHERE a2.active_flag = 1 AND 
a2.patient_id = :patient_id AND a2.needsLevel_careNeed = :careNeed

To resolve You can't specify target table 'TASK_ASSESSMENT' for update in FROM clause, rewrite the query to use JOIN instead of IN (in mysql you need to write something like this):

UPDATE TaskAssessment a
INNER JOIN TaskAssessment a2 ON (a2.id = a.id)
SET a.activeFlag = 0  
WHERE a2.active_flag = 1 AND 
a2.patient_id = :patient_id AND a2.needsLevel_careNeed = :careNeed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文