[英]How to update with inner join in HQL
How to update with inner join in HQL ? 如何在HQL中使用内部联接进行更新?
My query in SQL like this 我的SQL查询像这样
update u
更新你
set u.name = t.name设置u.name = t.name
from User u来自用户u
inner join Temp t on t.id = u.id内部联接在t.id = u.id上的温度t
and I try in HQL like 我尝试像
@Query("
@Query(“
update User u更新用户u
set u.name = ..?..设置u.name = ..?..
where u.id in (select id from Temp)u.id在哪里(从Temp中选择ID)
")”)
How can I get name in Temp to set in this query? 如何在Temp中获取名称以在此查询中进行设置?
thank you. 谢谢。
HQL as in Hive QL? Hive和Hive QL中一样? No, Hibernate QL.
不,休眠QL。
Hibernate provide a createSQLQuery method to let you call your native SQL statement directly. Hibernate提供了createSQLQuery方法,可让您直接调用本地SQL语句。 Native SQL Query approach based on ORACLE SQL:
基于ORACLE SQL的本机SQL查询方法:
update u
set u.name = (select t.name
from t
where t.id = u.id)
where exists (select 'X'
from t
where t.id = u.id)
and then apply the Hibernate stuff as per those object guidelines on parameters and bind variables. 然后根据这些对象准则将Hibernate内容应用于参数和绑定变量。 Not convinced an INNER JOIN is the way to go, but may be Hibernate is different for some approaches.
不确定是否可以使用INNER JOIN,但是Hibernate对于某些方法可能有所不同。
The JPQL syntax not supports the JOIN
keyword. JPQL语法不支持
JOIN
关键字。
But, if you have an entity relationship between User
and Temp
, you can try something like this: 但是,如果您在
User
和Temp
之间具有实体关系,则可以尝试如下操作:
UPDATE User u
SET u.name = u.temp.name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.