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 8e1411b4a..0397ab97e 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 @@ -135,6 +135,7 @@ public class BrokerImpl private static final int FLAG_FLUSH_REQUIRED = 2 << 8; private static final int FLAG_REMOTE_LISTENER = 2 << 9; private static final int FLAG_RETAINED_CONN = 2 << 10; + private static final int FLAG_TRANS_ENDING = 2 << 11; private static final Localizer _loc = Localizer.forPackage(BrokerImpl.class); @@ -1640,6 +1641,19 @@ public class BrokerImpl } } + /** + * Return whether the given transaction is ending, i.e. in the 2nd phase + * of a commit or rollback + */ + boolean isTransactionEnding() { + beginOperation(true); + try { + return (_flags & FLAG_TRANS_ENDING) != 0; + } finally { + endOperation(); + } + } + public boolean beginOperation(boolean syncTrans) { lock(); try { @@ -1722,6 +1736,7 @@ public class BrokerImpl try { assertActiveTransaction(); + _flags |= FLAG_TRANS_ENDING; endTransaction(status); if (_sync != null) _sync.afterCompletion(status); @@ -1746,6 +1761,7 @@ public class BrokerImpl } finally { _flags &= ~FLAG_ACTIVE; _flags &= ~FLAG_FLUSHED; + _flags &= ~FLAG_TRANS_ENDING; if (_transEventManager != null && _transEventManager.hasEndListeners()) { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java index db1cbf004..9617c98ca 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java @@ -824,7 +824,8 @@ public class StateManagerImpl return; boolean active = _broker.isActive(); - if (active) { + boolean ending = _broker.isTransactionEnding(); + if (active && !ending) { if (_broker.getOptimistic()) setPCState(_state.beforeOptimisticRead(this, field)); else