Index: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java =================================================================== --- openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (revision 496913) +++ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (working copy) @@ -300,7 +300,8 @@ throws Throwable { super.finalize(); if (!isClosed()) - free(); + free((_flags & FLAG_ACTIVE) != 0 ? Status.STATUS_ACTIVE : + Status.STATUS_NO_TRANSACTION); } /** @@ -1785,7 +1786,7 @@ // transaction; if that's true, then close now if ((_flags & FLAG_CLOSE_INVOKED) != 0 && _compat.getCloseOnManagedCommit()) - free(); + free(status); } catch (OpenJPAException ke) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), ke); @@ -3980,7 +3981,7 @@ _flags |= FLAG_CLOSE_INVOKED; if ((_flags & FLAG_ACTIVE) == 0) - free(); + free(Status.STATUS_NO_TRANSACTION); } finally { endOperation(); } @@ -3988,10 +3989,14 @@ /** * Free the resources used by this persistence manager. + * + * @param status The transactional status of the current context when + * free() was called. */ - protected void free() { + protected void free(int status) { RuntimeException err = null; - if ((_autoDetach & DETACH_CLOSE) != 0) { + if ((_autoDetach & DETACH_CLOSE) != 0 + && status != Status.STATUS_ROLLEDBACK) { try { detachAllInternal(_call); } catch (RuntimeException re) {