1
votes

How to update with inner join in HQL ?

My query in SQL like this

update u
set u.name = t.name
from User u
inner join Temp t on t.id = u.id

and I try in HQL like

@Query("
update User u
set u.name = ..?..
where u.id in (select id from Temp)
")

How can I get name in Temp to set in this query?
thank you.

2
how about some feedback?thebluephantom

2 Answers

0
votes

HQL as in Hive QL? No, Hibernate QL.

Hibernate provide a createSQLQuery method to let you call your native SQL statement directly. Native SQL Query approach based on ORACLE 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. Not convinced an INNER JOIN is the way to go, but may be Hibernate is different for some approaches.

0
votes

The JPQL syntax not supports the JOIN keyword.

But, if you have an entity relationship between User and Temp, you can try something like this:

UPDATE User u
SET u.name = u.temp.name