TransactionTemplate catches undeclared checked exception and rethrows it as UndeclaredThrowableException (SPR-6361)
This commit is contained in:
parent
eb0b4f0cbd
commit
a741410421
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.transaction.support;
|
package org.springframework.transaction.support;
|
||||||
|
|
||||||
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
|
@ -123,7 +125,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TransactionStatus status = this.transactionManager.getTransaction(this);
|
TransactionStatus status = this.transactionManager.getTransaction(this);
|
||||||
T result = null;
|
T result;
|
||||||
try {
|
try {
|
||||||
result = action.doInTransaction(status);
|
result = action.doInTransaction(status);
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +139,11 @@ public class TransactionTemplate extends DefaultTransactionDefinition
|
||||||
rollbackOnException(status, err);
|
rollbackOnException(status, err);
|
||||||
throw 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);
|
this.transactionManager.commit(status);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue