diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index 58dd46926..2ab7e6b0d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -3321,8 +3321,17 @@ public class BrokerImpl if (call == null) call = _call; - new DetachManager(this, true, call).detachAll - (new ManagedObjectCollection(states)); + // Make sure ALL entities are detached, even new ones that are loaded + // during the detach processing + boolean origCascade = _compat.getCascadeWithDetach(); + _compat.setCascadeWithDetach(true); + try { + new DetachManager(this, true, call) + .detachAll(new ManagedObjectCollection(states)); + } + finally { + _compat.setCascadeWithDetach(origCascade); + } } public Object attach(Object obj, boolean copyNew, OpCallbacks call) {