JPQL: Update if not exists
I'm trying to achieve something like this in may JPA/Hibernate/MySQL
application:
UPDATE UserRating ur SET ur.item = :newItem WHERE ur.item = :oldItem AND
NOT EXISTS (SELECT ur2 FROM UserRating ur2 WHERE ur.user = ur2.user AND
ur2.item = :newItem)
So, I want to update some rows only if they will be unique (user/item
combination must be unique).
I'm getting
Caused by: java.sql.SQLException: You can't specify target table
'user_rating' for update in FROM clause
with the current JPQL.
No comments:
Post a Comment