gpt4 book ai didi

Java Hibernate HQL无法指定目标表

转载 作者:行者123 更新时间:2023-11-29 12:23:31 25 4
gpt4 key购买 nike

我正在阅读用户 @JB Nizet 的帖子

Hibernate Exception on MySQL Cross Join Query

后来我尝试了自己的代码

我有一个这样的 HQL。

update Student set newField='newField',anotherFieldsToBeUpdated where .... 
and id in
(select s.id from Student s where s.school=:school)
-->[Student->School]many to one relationship....

但仍然抛出臭名昭著的

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

我想知道是否仍然存在不使用另一个不同的选择或使用临时表的解决方案。

最佳答案

当您仅访问同一张表时,您可以将您的限制组合在一起:

update Student set newField = :newField where ... and school = :school

关于Java Hibernate HQL无法指定目标表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685629/

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