I have two models, say :
BlogPost(title, message)
Tags(name)
Both have a ManyToMany relationship defined.
Using JPQL, I delete a list of BlogPost with this query:
DELETE FROM BlogPost b WHERE b IN :list
(:list is a List from a previous SELECT requet).
Doing so, I have a ConstraintViolationException because of the relation between BlogPost and Tags.
Is there a way to delete the relation without deleting the Tags using JPQL?
Thanks for your help!
I’ll answer myself with the solution I came up. I’m not sure it’s the best one, but at least, it works.
Since you want to bulk delete something that have a ManyToMany related items, you first have to delete the relation (in the join table), or do a loop and for each item, delete manually (insane and too much heavy).
So, since JPQL does not allow to do it, a possible way is to make a native SQL query for deleting the id you want in the related table, and then, do the bulk delete.