Class PersistenceExceptionTranslationPostProcessor

java.lang.Object
org.springframework.aop.framework.ProxyConfig
org.springframework.aop.framework.ProxyProcessorSupport
org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
All Implemented Interfaces:
Serializable, org.springframework.aop.framework.AopInfrastructureBean, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor, org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor, org.springframework.core.Ordered

public class PersistenceExceptionTranslationPostProcessor extends org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
Bean post-processor that automatically applies persistence exception translation to any bean marked with Spring's @Repository annotation, adding a corresponding PersistenceExceptionTranslationAdvisor to the exposed proxy (either an existing AOP proxy or a newly generated proxy that implements all of the target's interfaces).

Translates native resource exceptions to Spring's DataAccessException hierarchy. Autodetects beans that implement the PersistenceExceptionTranslator interface, which are subsequently asked to translate candidate exceptions.

All of Spring's applicable resource factories (e.g. org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) implement the PersistenceExceptionTranslator interface out of the box. As a consequence, all that is usually needed to enable automatic exception translation is marking all affected beans (such as Repositories or DAOs) with the @Repository annotation, along with defining this post-processor as a bean in the application context.

As of 5.3, PersistenceExceptionTranslator beans will be sorted according to Spring's dependency ordering rules: see Ordered and Order. Note that such beans will get retrieved from any scope, not just singleton scope, as of this 5.3 revision.

Since:
2.0
Author:
Rod Johnson, Juergen Hoeller
See Also:
  • Field Summary

    Fields inherited from class org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor

    advisor, beforeExistingAdvisors

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
     
    void
    setRepositoryAnnotationType(Class<? extends Annotation> repositoryAnnotationType)
    Set the 'repository' annotation type.

    Methods inherited from class org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor

    isEligible, prepareProxyFactory

    Methods inherited from class org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor

    customizeProxyFactory, determineBeanType, isEligible, postProcessAfterInitialization, setBeforeExistingAdvisors

    Methods inherited from class org.springframework.aop.framework.ProxyProcessorSupport

    evaluateProxyInterfaces, getOrder, getProxyClassLoader, isConfigurationCallbackInterface, isInternalLanguageInterface, setBeanClassLoader, setOrder, setProxyClassLoader

    Methods inherited from class org.springframework.aop.framework.ProxyConfig

    copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor

    postProcessBeforeInitialization

    Methods inherited from interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor

    postProcessAfterInstantiation, postProcessBeforeInstantiation, postProcessProperties

    Methods inherited from interface org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor

    determineCandidateConstructors, getEarlyBeanReference, predictBeanType
  • Constructor Details

    • PersistenceExceptionTranslationPostProcessor

      public PersistenceExceptionTranslationPostProcessor()
  • Method Details

    • setRepositoryAnnotationType

      public void setRepositoryAnnotationType(Class<? extends Annotation> repositoryAnnotationType)
      Set the 'repository' annotation type. The default repository annotation type is the Repository annotation.

      This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a class has a repository role.

      Parameters:
      repositoryAnnotationType - the desired annotation type
    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Overrides:
      setBeanFactory in class org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor