类 HibernateExceptionTranslator
- java.lang.Object
- org.springframework.orm.hibernate5.HibernateExceptionTranslator
- 所有已实现的接口:
PersistenceExceptionTranslator
- 直接已知子类:
LocalSessionFactoryBean
public class HibernateExceptionTranslator extends Object implements PersistenceExceptionTranslator
PersistenceExceptionTranslator
capable of translatingHibernateException
instances to Spring'sDataAccessException
hierarchy. As of Spring 4.3.2 and Hibernate 5.2, it also converts standard JPAPersistenceException
instances.Extended by
LocalSessionFactoryBean
, so there is no need to declare this translator in addition to aLocalSessionFactoryBean
.When configuring the container with
@Configuration
classes, a@Bean
of this type must be registered manually.
构造器概要
构造器 构造器 说明 HibernateExceptionTranslator()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected DataAccessException
convertHibernateAccessException(HibernateException ex)
Convert the given HibernateException to an appropriate exception from theorg.springframework.dao
hierarchy.DataAccessException
translateExceptionIfPossible(RuntimeException ex)
Translate the given runtime exception thrown by a persistence framework to a corresponding exception from Spring's genericDataAccessException
hierarchy, if possible.
构造器详细资料
HibernateExceptionTranslator
public HibernateExceptionTranslator()
方法详细资料
translateExceptionIfPossible
public DataAccessException translateExceptionIfPossible(RuntimeException ex)
从接口复制的说明:PersistenceExceptionTranslator
Translate the given runtime exception thrown by a persistence framework to a corresponding exception from Spring's genericDataAccessException
hierarchy, if possible.Do not translate exceptions that are not understood by this translator: for example, if coming from another persistence framework, or resulting from user code or otherwise unrelated to persistence.
Of particular importance is the correct translation to DataIntegrityViolationException, for example on constraint violation. Implementations may use Spring JDBC's sophisticated exception translation to provide further information in the event of SQLException as a root cause.
- 指定者:
translateExceptionIfPossible
在接口中PersistenceExceptionTranslator
- 参数:
ex
- a RuntimeException to translate- 返回:
- the corresponding DataAccessException (or
null
if the exception could not be translated, as in this case it may result from user code rather than from an actual persistence problem) - 另请参阅:
DataIntegrityViolationException
,SQLExceptionTranslator
convertHibernateAccessException
protected DataAccessException convertHibernateAccessException(HibernateException ex)
Convert the given HibernateException to an appropriate exception from theorg.springframework.dao
hierarchy.- 参数:
ex
- HibernateException that occurred- 返回:
- a corresponding DataAccessException
- 另请参阅:
SessionFactoryUtils.convertHibernateAccessException(org.hibernate.HibernateException)