使用 set 子句中的子查询更新 Hibernate HQL
我正在尝试在 hibernate HQL 中使用 set 子句中的子选择进行更新,例如:
update UserObject set code = (select n.code from SomeUserObject n where n.id = 1000)
它不起作用,不支持吗?
谢谢
乌多
I'm trying to do an update in hibernate HQL with a subselect in a set clause like:
update UserObject set code = (select n.code from SomeUserObject n where n.id = 1000)
It isnt working, it is not supported?
Thanks
Udo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 Hibernate 文档:
虽然文档没有明确提及有关 set 部分的限制,但人们可以解释子查询仅在 where 子句中受支持。但是......
我发现了一个关于批量更新问题的4年前(叹息)问题(HHH-1658),据记者称,以下方法有效:
我想知道在 from 子句中使用别名是否有帮助。看来还是有一些奇怪的地方。
From the Hibernate documentation:
While the documentation doesn't explicitly mentions a restriction about the set part, one could interpret that sub-queries are only supported in the where-clause. But...
I found an 4 years old (sigh) issue about bulk update problems (HHH-1658) and according to the reporter, the following works:
I wonder if using an alias in the from-clause would help. Looks like there is some weirdness anyway.
我遇到了同样的问题,发现您需要将批量更新放入事务中:
I had the same problem, discovered that you need to put bulk updates in side a transaction: