How to use connection in HQL update?

I know how to combine tables in an SQL update, but how to do it in HQL?

Long story. I have elements that I process in perspective. Each of them runs as an identifier, and I have a many-to-many relationship between elements and runs (which are in an additional table).

Now I want to set the state of all the elements used in a particular run. The naive approach is as follows:

update Items item
set item.statue = :done
where item.state = :new
  and :run in item.runs

The last line does not work. Hibernate cannot turn a bag of runs into something that can be used in a where clause. What solution?

+3
source share
1 answer

item.runs (item.runs). , , , HQL . , , - :

update Items i1
set i1.statue = :done
where i1.state = :new
and i1 in (
  select i2
  from Items i2
  where :run in elements(i2.runs)
) 
+4

Source: https://habr.com/ru/post/1719506/


All Articles