【问题标题】:Java Hibernate HQL can't specify target tableJava Hibernate HQL 无法指定目标表
【发布时间】:2015-04-25 11:25:16
【问题描述】:

我正在阅读用户 @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

我想知道是否仍然存在没有using another different select 或使用a temporal table 的解决方案。

【问题讨论】:

  • 您能用文字说出您的查询目的是什么吗?学生和学校是什么关系?

标签: java mysql hibernate hql named-query


【解决方案1】:

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

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

【讨论】:

  • 很高兴我能帮上忙。如果您需要更多信息,请参阅HQL 规范。
猜你喜欢
  • 1970-01-01
  • 2011-08-25
  • 1970-01-01
  • 2014-01-29
  • 1970-01-01
  • 1970-01-01
  • 2010-11-18
  • 2016-06-24
  • 1970-01-01
相关资源
最近更新 更多