[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] control order of em.remove() calls
|
Dear all,
I have an issue I can't solve.
My data structure has a parent child relation, like..
class A {
A parent;
List<A> children (cascade=ALL)
}
Now I want to remove a part of the tree. As far as I understand the order of the delete statements is essential. What I actually do is a recursive method that deletes all the instances beginning from the leaves.
This looks more or less like :
remove(A a) {
recursiveRemove(a);
a.parent.children.remove(a);
}
removeRecursive(A a) {
for all children of a {
removeRecursive(a);
a.parent.children.remove(a);
}
entityManager.remove(a);
}
I know the entityManager.remove() calls come in in the correct (leaf first) order, but JPA seems to execute in another order. It tries to delete the parent first, which causes a violation of the constraint.
Am I completely on the wrong path or is there a way to control execution order of JPA-statements for such parent/child relations? I thought that should be the case anyways.. :)
BTW. when just letting JPA remove the data with em.remove(rootA) I get the same problem. That is actually why I implemented the recursive call.
Thank you very much for your support.