How to use join in an HQL update?
hibernate, java, join
Solution
Try changing item.runs to elements(item.runs). I'm not sure it will work for an update, though, because joins in HQL updates usually need to be expressed in a subselect. So if it doesn't work, try something like:
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)
)
Problem
I know how to join tables in an SQL update but how do I do it in HQL? Long story: I have items which I process in a run. Each run as an ID and I have a many-to-many relation between items and runs (which is in an extra table). Now I want to set the state of all items used in a certain run. The naive approach looks like this: ``` update Items item set item.statue = :done where item.state = :new and :run in item.runs ``` The last line doesn't work. Hibernate can't turn the bag with runs into something that can be used in a where clause. What's the solution?