org.springframework.dao.support

Class PersistenceExceptionTranslationInterceptor

  • java.lang.Object
    • org.springframework.dao.support.PersistenceExceptionTranslationInterceptor
    • Constructor Detail

      • PersistenceExceptionTranslationInterceptor

        public PersistenceExceptionTranslationInterceptor(PersistenceExceptionTranslator pet)
        Create a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.
        Parameters:
        pet - the PersistenceExceptionTranslator to use
      • PersistenceExceptionTranslationInterceptor

        public PersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory)
        Create a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.
        Parameters:
        beanFactory - the ListableBeanFactory to obtaining all PersistenceExceptionTranslators from
    • Method Detail

      • setAlwaysTranslate

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

      • afterPropertiesSet

        public void afterPropertiesSet()
        Description copied from interface: InitializingBean
        Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

        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:
        afterPropertiesSet in interface InitializingBean
      • invoke

        public java.lang.Object invoke(MethodInvocation mi)
                                throws java.lang.Throwable
        Description copied from interface: MethodInterceptor
        Implement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invoke Joinpoint.proceed().
        Specified by:
        invoke in interface MethodInterceptor
        Parameters:
        mi - the method invocation joinpoint
        Returns:
        the result of the call to Joinpoint.proceed(); might be intercepted by the interceptor
        Throws:
        java.lang.Throwable - if the interceptors or the target object throws an exception
      • detectPersistenceExceptionTranslators

        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
        See Also:
        ChainedPersistenceExceptionTranslator