Class PersistenceExceptionTranslationInterceptor
- All Implemented Interfaces:
- Advice,- Interceptor,- MethodInterceptor,- Aware,- BeanFactoryAware,- InitializingBean
Delegates to the given PersistenceExceptionTranslator to translate
 a RuntimeException thrown into Spring's DataAccessException hierarchy
 (if appropriate). If the RuntimeException in question is declared on the
 target method, it is always propagated as-is (with no translation applied).
- Since:
- 2.0
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new PersistenceExceptionTranslationInterceptor.Create a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.Create a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected PersistenceExceptionTranslatorDetect all PersistenceExceptionTranslators in the given BeanFactory.Implement this method to perform extra treatments before and after the invocation.voidsetAlwaysTranslate(boolean alwaysTranslate) Specify whether to always translate the exception ("true"), or whether throw the raw exception when declared, i.e.voidsetBeanFactory(BeanFactory beanFactory) Callback that supplies the owning factory to a bean instance.voidSpecify the PersistenceExceptionTranslator to use.
- 
Constructor Details- 
PersistenceExceptionTranslationInterceptorpublic PersistenceExceptionTranslationInterceptor()Create a new PersistenceExceptionTranslationInterceptor. Needs to be configured with a PersistenceExceptionTranslator afterwards.- See Also:
 
- 
PersistenceExceptionTranslationInterceptorCreate a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.- Parameters:
- pet- the PersistenceExceptionTranslator to use
 
- 
PersistenceExceptionTranslationInterceptorCreate a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.- Parameters:
- beanFactory- the ListableBeanFactory to obtaining all PersistenceExceptionTranslators from
 
 
- 
- 
Method Details- 
setPersistenceExceptionTranslatorSpecify the PersistenceExceptionTranslator to use.Default is to autodetect all PersistenceExceptionTranslators in the containing BeanFactory, using them in a chain. - See Also:
 
- 
setAlwaysTranslatepublic void setAlwaysTranslate(boolean alwaysTranslate) Specify whether to always translate the exception ("true"), or whether throw the raw exception when declared, i.e. when the originating method signature's exception declarations allow for the raw exception to be thrown ("false").Default is "false". Switch this flag to "true" in order to always translate applicable exceptions, independent of the originating method signature. Note that the originating method does not have to declare the specific exception. Any base class will do as well, even throws Exception: As long as the originating method does explicitly declare compatible exceptions, the raw exception will be rethrown. If you would like to avoid throwing raw exceptions in any case, switch this flag to "true".
- 
setBeanFactoryDescription copied from interface:BeanFactoryAwareCallback 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.- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Parameters:
- beanFactory- owning BeanFactory (never- null). The bean can immediately call methods on the factory.
- Throws:
- BeansException- in case of initialization errors
- See Also:
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
invokeDescription copied from interface:MethodInterceptorImplement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invokeJoinpoint.proceed().- Specified by:
- invokein interface- MethodInterceptor
- Parameters:
- mi- the method invocation joinpoint
- Returns:
- the result of the call to Joinpoint.proceed(); might be intercepted by the interceptor
- Throws:
- Throwable- if the interceptors or the target object throws an exception
 
- 
detectPersistenceExceptionTranslatorsprotected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory bf) Detect all PersistenceExceptionTranslators in the given BeanFactory.- Parameters:
- bf- the ListableBeanFactory to obtain PersistenceExceptionTranslators from
- Returns:
- a chained PersistenceExceptionTranslator, combining all PersistenceExceptionTranslators found in the given bean factory
- See Also:
 
 
-