public class

PersistenceExceptionTranslationInterceptor

extends Object
implements BeanFactoryAware InitializingBean
java.lang.Object
   ↳ org.springframework.dao.support.PersistenceExceptionTranslationInterceptor

Class Overview

AOP Alliance MethodInterceptor that provides persistence exception translation based on a given PersistenceExceptionTranslator.

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).

Summary

Public Constructors
PersistenceExceptionTranslationInterceptor()
Create a new PersistenceExceptionTranslationInterceptor.
PersistenceExceptionTranslationInterceptor(PersistenceExceptionTranslator persistenceExceptionTranslator)
Create a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.
PersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory)
Create a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.
Public Methods
void afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
Object invoke(MethodInvocation mi)
void setAlwaysTranslate(boolean alwaysTranslate)
Specify whether to always translate the exception ("true"), or whether throw the raw exception when declared, i.e.
void setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
void setPersistenceExceptionTranslator(PersistenceExceptionTranslator pet)
Specify the PersistenceExceptionTranslator to use.
Protected Methods
PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory)
Detect all PersistenceExceptionTranslators in the given BeanFactory.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.BeanFactoryAware
From interface org.springframework.beans.factory.InitializingBean

Public Constructors

public PersistenceExceptionTranslationInterceptor ()

Create a new PersistenceExceptionTranslationInterceptor. Needs to be configured with a PersistenceExceptionTranslator afterwards.

public PersistenceExceptionTranslationInterceptor (PersistenceExceptionTranslator persistenceExceptionTranslator)

Create a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.

Parameters
persistenceExceptionTranslator the PersistenceExceptionTranslator to use

public PersistenceExceptionTranslationInterceptor (ListableBeanFactory beanFactory)

Create a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.

Parameters
beanFactory the ListableBeanFactory to obtaining all PersistenceExceptionTranslators from

Public Methods

public void afterPropertiesSet ()

Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

public Object invoke (MethodInvocation mi)

Throws
Throwable

public 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 from 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".

public void setBeanFactory (BeanFactory beanFactory)

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 afterPropertiesSet() or a custom init-method.

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

public void setPersistenceExceptionTranslator (PersistenceExceptionTranslator pet)

Specify the PersistenceExceptionTranslator to use.

Default is to autodetect all PersistenceExceptionTranslators in the containing BeanFactory, using them in a chain.

Protected Methods

protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators (ListableBeanFactory beanFactory)

Detect all PersistenceExceptionTranslators in the given BeanFactory.

Parameters
beanFactory the ListableBeanFactory to obtaining all PersistenceExceptionTranslators from
Returns
  • a chained PersistenceExceptionTranslator, combining all PersistenceExceptionTranslators found in the factory