Class MyBatisExceptionTranslator

java.lang.Object
org.mybatis.spring.MyBatisExceptionTranslator
All Implemented Interfaces:
org.springframework.dao.support.PersistenceExceptionTranslator

public class MyBatisExceptionTranslator
extends java.lang.Object
implements org.springframework.dao.support.PersistenceExceptionTranslator
Default exception translator. Translates MyBatis SqlSession returned exception into a Spring DataAccessException using Spring's SQLExceptionTranslator Can load SQLExceptionTranslator eagerly or when the first exception is translated.
Author:
Eduardo Macarron
  • Constructor Summary

    Constructors
    Constructor Description
    MyBatisExceptionTranslator​(java.util.function.Supplier<org.springframework.jdbc.support.SQLExceptionTranslator> exceptionTranslatorSupplier, boolean exceptionTranslatorLazyInit)
    Creates a new PersistenceExceptionTranslator instance with specified SQLExceptionTranslator.
    MyBatisExceptionTranslator​(javax.sql.DataSource dataSource, boolean exceptionTranslatorLazyInit)
    Creates a new PersistenceExceptionTranslator instance with SQLErrorCodeSQLExceptionTranslator.
  • Method Summary

    Modifier and Type Method Description
    org.springframework.dao.DataAccessException translateExceptionIfPossible​(java.lang.RuntimeException e)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MyBatisExceptionTranslator

      public MyBatisExceptionTranslator​(javax.sql.DataSource dataSource, boolean exceptionTranslatorLazyInit)
      Creates a new PersistenceExceptionTranslator instance with SQLErrorCodeSQLExceptionTranslator.
      Parameters:
      dataSource - DataSource to use to find metadata and establish which error codes are usable.
      exceptionTranslatorLazyInit - if true, the translator instantiates internal stuff only the first time will have the need to translate exceptions.
    • MyBatisExceptionTranslator

      public MyBatisExceptionTranslator​(java.util.function.Supplier<org.springframework.jdbc.support.SQLExceptionTranslator> exceptionTranslatorSupplier, boolean exceptionTranslatorLazyInit)
      Creates a new PersistenceExceptionTranslator instance with specified SQLExceptionTranslator.
      Parameters:
      exceptionTranslatorSupplier - Supplier for creating a SQLExceptionTranslator instance
      exceptionTranslatorLazyInit - if true, the translator instantiates internal stuff only the first time will have the need to translate exceptions.
      Since:
      2.0.3
  • Method Details

    • translateExceptionIfPossible

      public org.springframework.dao.DataAccessException translateExceptionIfPossible​(java.lang.RuntimeException e)
      Specified by:
      translateExceptionIfPossible in interface org.springframework.dao.support.PersistenceExceptionTranslator