类 HibernateExceptionTranslator
- java.lang.Object
- org.springframework.orm.hibernate4.HibernateExceptionTranslator
- 所有已实现的接口:
PersistenceExceptionTranslator
- 直接已知子类:
LocalSessionFactoryBean
public class HibernateExceptionTranslator extends Object implements PersistenceExceptionTranslator
PersistenceExceptionTranslatorcapable of translatingHibernateExceptioninstances to Spring'sDataAccessExceptionhierarchy.Extended by
LocalSessionFactoryBean, so there is no need to declare this translator in addition to aLocalSessionFactoryBean.When configuring the container with
@Configurationclasses, a@Beanof this type must be registered manually.- 从以下版本开始:
- 3.1
- 作者:
- Juergen Hoeller
- 另请参阅:
PersistenceExceptionTranslationPostProcessor,SessionFactoryUtils.convertHibernateAccessException(HibernateException)
构造器概要
构造器 构造器 说明 HibernateExceptionTranslator()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected DataAccessExceptionconvertHibernateAccessException(HibernateException ex)Convert the given HibernateException to an appropriate exception from theorg.springframework.daohierarchy.DataAccessExceptiontranslateExceptionIfPossible(RuntimeException ex)Translate the given runtime exception thrown by a persistence framework to a corresponding exception from Spring's genericDataAccessExceptionhierarchy, if possible.
构造器详细资料
HibernateExceptionTranslator
public HibernateExceptionTranslator()
方法详细资料
translateExceptionIfPossible
public DataAccessException translateExceptionIfPossible(RuntimeException ex)
从接口复制的说明:PersistenceExceptionTranslatorTranslate the given runtime exception thrown by a persistence framework to a corresponding exception from Spring's genericDataAccessExceptionhierarchy, 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
nullif 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.daohierarchy.- 参数:
ex- HibernateException that occured- 返回:
- a corresponding DataAccessException
- 另请参阅:
SessionFactoryUtils.convertHibernateAccessException(org.hibernate.HibernateException)