/** * Return the exception that was the first to be thrown within the failed transaction: * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); }
/** * Return the exception that was the first to be thrown within the failed transaction: * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); }
@Test public void testTransactionCommitWithRollbackException() { given(manager.getTransaction()).willReturn(tx); given(tx.getRollbackOnly()).willReturn(true); willThrow(new RollbackException()).given(tx).commit(); final List<String> l = new ArrayList<>(); l.add("test"); assertTrue(!TransactionSynchronizationManager.hasResource(factory)); assertTrue(!TransactionSynchronizationManager.isSynchronizationActive()); try { Object result = tt.execute(new TransactionCallback() { @Override public Object doInTransaction(TransactionStatus status) { assertTrue(TransactionSynchronizationManager.hasResource(factory)); EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush(); return l; } }); assertSame(l, result); } catch (TransactionSystemException tse) { // expected assertTrue(tse.getCause() instanceof RollbackException); } assertTrue(!TransactionSynchronizationManager.hasResource(factory)); assertTrue(!TransactionSynchronizationManager.isSynchronizationActive()); verify(manager).flush(); verify(manager).close(); }
assertTrue(tse.getCause() instanceof RollbackException);
assertTrue(ex.getCause() instanceof UOWException); assertSame(rex, ex.getRootCause()); assertSame(rex, ex.getMostSpecificCause());
/** * Return the exception that was the first to be thrown within the failed transaction: * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); }
/** * Return the exception that was the first to be thrown within the failed transaction: * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); }
/** * Utility for using TransactionTemplate when we know that a rollback might happen and just want * to ignore it */ protected <T> T executeIgnoreRollback(TransactionCallback<T> action, T rollbackValue) { try { // Try to create the mutex in a new TX return this.newTransactionTemplate.execute(action); } catch (TransactionSystemException e) { if (e.getCause() instanceof RollbackException) { // Ignore rollbacks return rollbackValue; } // re-throw exception with unhandled cause throw e; } } }
/** * Utility for using TransactionTemplate when we know that a rollback might happen and just want * to ignore it */ protected <T> T executeIgnoreRollback(TransactionCallback<T> action, T rollbackValue) { try { // Try to create the mutex in a new TX return this.newTransactionTemplate.execute(action); } catch (TransactionSystemException e) { if (e.getCause() instanceof RollbackException) { // Ignore rollbacks return rollbackValue; } // re-throw exception with unhandled cause throw e; } } }