MyBatisExceptionTranslator loose PersistenceException message
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.9k
- Forks
- 2.6k
- Avg merge
- 3d 4m
- Merged PRs (30d)
- 8
Description
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).
public DataAccessException translateExceptionIfPossible(RuntimeException e) {
// customized extension: store errorMessage from original exception
StringBuilder errorMessage = new StringBuilder(e.getMessage()).append("\n");
if (e instanceof PersistenceException) {
if (e.getCause() instanceof PersistenceException) {
e = (PersistenceException) e.getCause();
// customized extension: add error message from underlying exception
errorMessage.append(e.getMessage()).append("\n");
}
if (e.getCause() instanceof SQLException) {
this.initExceptionTranslator();
// customized extension: pass errorMessage
return this.exceptionTranslator.translate(errorMessage.toString(), null, (SQLException) e.getCause());
}
return new MyBatisSystemException(e);
}
return null;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at MyBatisExceptionTranslator and its translateExceptionIfPossible method, then trace how PersistenceException messages reach DataAccessException. The issue is done when the original ErrorContext message is preserved during translation, including when an underlying SQLException is handled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100