Top Description Fields Constructors Methods
org.springframework.dao.annotation

public Class PersistenceExceptionTranslationPostProcessor

extends AbstractBeanFactoryAwareAdvisingPostProcessor
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.lang.annotation.Annotation, org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor, org.springframework.beans.factory.BeanFactory, .ListableBeanFactory, org.springframework.stereotype.Repository, org.springframework.util.Assert

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 org.springframework.core.Ordered and org.springframework.core.annotation.Order. Note that such beans will get retrieved from any scope, not just singleton scope, as of this 5.3 revision.

Authors
Rod Johnson, Juergen Hoeller
Since
2.0
See Also
PersistenceExceptionTranslationAdvisor, org.springframework.stereotype.Repository, org.springframework.dao.DataAccessException, org.springframework.dao.support.PersistenceExceptionTranslator

Field Summary

Modifier and TypeField and Description
private Class<? extends Annotation>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Overrides org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor.setBeanFactory.

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.
public void
setRepositoryAnnotationType(Class<? extends Annotation>
the desired annotation type
repositoryAnnotationType
)

Set the 'repository' annotation type.

Inherited from org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor:
isEligibleprepareProxyFactory

Field Detail

repositoryAnnotationTypeback to summary
private Class<? extends Annotation> repositoryAnnotationType

Constructor Detail

PersistenceExceptionTranslationPostProcessorback to summary
public PersistenceExceptionTranslationPostProcessor()

Method Detail

setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Overrides org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor.setBeanFactory.

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
setRepositoryAnnotationTypeback to summary
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:Class<? extends Annotation>

the desired annotation type