I am trying to delete a large number of rows from MOTHER
thanks to a JPQL query.
The Mother
class is defined as follows:
@E
DELETE (and INSERT) do not cascade via relationships in JPQL query. This is clearly spelled in specification:
A delete operation only applies to entities of the specified class and its subclasses. It does not cascade to related entities.
Luckily persist and removal via entity manager do (when there is cascade attribute defined).
What you can do:
Code is something like this:
String selectQuery = "SELECT m FROM Mother m WHERE some_condition";
List mothersToRemove = entityManager
.createQuery(selectQuery)
.getResultStream()
.forEach(em::remove);