You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When MyBatis PersistenceException is translated to DataAccessException by MyBatisExceptionTranslator the original message from PersistenceException (ErrorContext message) gets lost. I've implemented my own ExceptionTranslator that preserves the original message - feel free to use it to update your MyBatisExceptionTranslator (my changes are marked with comments).
publicDataAccessExceptiontranslateExceptionIfPossible(RuntimeExceptione) {
// customized extension: store errorMessage from original exception StringBuildererrorMessage = newStringBuilder(e.getMessage()).append("\n");
if (einstanceofPersistenceException) {
if (e.getCause() instanceofPersistenceException) {
e = (PersistenceException) e.getCause();
// customized extension: add error message from underlying exceptionerrorMessage.append(e.getMessage()).append("\n");
}
if (e.getCause() instanceofSQLException) {
this.initExceptionTranslator();
// customized extension: pass errorMessage returnthis.exceptionTranslator.translate(errorMessage.toString(), null, (SQLException) e.getCause());
}
returnnewMyBatisSystemException(e);
}
returnnull;
}
The text was updated successfully, but these errors were encountered:
When MyBatis
PersistenceException
is translated toDataAccessException
byMyBatisExceptionTranslator
the original message fromPersistenceException
(ErrorContext
message) gets lost. I've implemented my ownExceptionTranslator
that preserves the original message - feel free to use it to update yourMyBatisExceptionTranslator
(my changes are marked with comments).The text was updated successfully, but these errors were encountered: