Skip to content

Commit a1104b0

Browse files
committed
Preserve Spring's Transaction exceptions (related to mybatis#115)
1 parent b5cc9fa commit a1104b0

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/org/mybatis/spring/MyBatisExceptionTranslator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.dao.support.PersistenceExceptionTranslator;
2525
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
2626
import org.springframework.jdbc.support.SQLExceptionTranslator;
27+
import org.springframework.transaction.TransactionException;
2728

2829
/**
2930
* Default exception translator.
@@ -72,6 +73,8 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
7273
if (e.getCause() instanceof SQLException) {
7374
this.initExceptionTranslator();
7475
return this.exceptionTranslator.translate(e.getMessage() + "\n", null, (SQLException) e.getCause());
76+
} else if (e.getCause() instanceof TransactionException) {
77+
throw (TransactionException) e.getCause();
7578
}
7679
return new MyBatisSystemException(e);
7780
}

0 commit comments

Comments
 (0)