spring-framework / org.springframework.dao.annotation / PersistenceExceptionTranslationPostProcessor

PersistenceExceptionTranslationPostProcessor

open class PersistenceExceptionTranslationPostProcessor : AbstractBeanFactoryAwareAdvisingPostProcessor

Bean post-processor that automatically applies persistence exception translation to any bean marked with Spring's @org.springframework.stereotype.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 org.springframework.dao.DataAccessException hierarchy. Autodetects beans that implement the org.springframework.dao.support.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.

Author
Rod Johnson

Author
Juergen Hoeller

Since
2.0

See Also
PersistenceExceptionTranslationAdvisororg.springframework.stereotype.Repositoryorg.springframework.dao.DataAccessExceptionorg.springframework.dao.support.PersistenceExceptionTranslator

Constructors

<init>

PersistenceExceptionTranslationPostProcessor()

Bean post-processor that automatically applies persistence exception translation to any bean marked with Spring's @org.springframework.stereotype.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 org.springframework.dao.DataAccessException hierarchy. Autodetects beans that implement the org.springframework.dao.support.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.

Functions

setBeanFactory

open fun setBeanFactory(beanFactory: BeanFactory): Unit

setRepositoryAnnotationType

open fun setRepositoryAnnotationType(repositoryAnnotationType: Class<out Annotation>): Unit

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.