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 2632b26c8..daa053424 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 @@ -1757,11 +1757,11 @@ public class BrokerImpl } catch (OpenJPAException ke) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), ke); - throw ke; + throw translateManagedCompletionException(ke); } catch (RuntimeException re) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), re); - throw new StoreException(re); + throw translateManagedCompletionException(new StoreException(re)); } finally { endOperation(); } @@ -1789,11 +1789,11 @@ public class BrokerImpl } catch (OpenJPAException ke) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), ke); - throw ke; + throw translateManagedCompletionException(ke); } catch (RuntimeException re) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), re); - throw new StoreException(re); + throw translateManagedCompletionException(new StoreException(re)); } finally { _flags &= ~FLAG_ACTIVE; _flags &= ~FLAG_FLUSHED; @@ -1813,6 +1813,15 @@ public class BrokerImpl } } + /** + * If we're in a managed transaction, use our implicit behavior exception + * translator to translate before/afterCompletion callback errors. + */ + private RuntimeException translateManagedCompletionException + (RuntimeException re) { + return (!_managed || _extrans == null) ? re : _extrans.translate(re); + } + /** * Flush safely, catching reentrant calls. */ diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java index 3db3a3119..2f3b96d89 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java @@ -48,7 +48,7 @@ public class PersistenceExceptions * and {@link NonUniqueResultException} in accordance with * section 3.7 of the EJB 3.0 specification. */ - static RuntimeExceptionTranslator getRollbackTranslator + public static RuntimeExceptionTranslator getRollbackTranslator (final OpenJPAEntityManager em) { return new RuntimeExceptionTranslator() { private boolean throwing = false;