TransactionTemplate catches undeclared checked exception and rethrows it as UndeclaredThrowableException (SPR-6361)

This commit is contained in:
Juergen Hoeller 2009-11-19 16:36:15 +00:00
parent eb0b4f0cbd
commit a741410421
1 changed files with 8 additions and 1 deletions

View File

@ -16,6 +16,8 @@
package org.springframework.transaction.support;
import java.lang.reflect.UndeclaredThrowableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -123,7 +125,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition
}
else {
TransactionStatus status = this.transactionManager.getTransaction(this);
T result = null;
T result;
try {
result = action.doInTransaction(status);
}
@ -137,6 +139,11 @@ public class TransactionTemplate extends DefaultTransactionDefinition
rollbackOnException(status, err);
throw err;
}
catch (Exception ex) {
// Transactional code threw unexpected exception -> rollback
rollbackOnException(status, ex);
throw new UndeclaredThrowableException(ex, "TransactionCallback threw undeclared checked exception");
}
this.transactionManager.commit(status);
return result;
}