Announcement Announcement Module
Collapse
No announcement yet.
Turning off PersistenceExceptionTranslationPostProcessor instantiation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Turning off PersistenceExceptionTranslationPostProcessor instantiation

    Hi,

    ist it possible to completely turn off the (auto-) instantiation of PersistenceExceptionTranslationPostProcessor?

    Currently we are using the hack of declaring a bean with the "generated" name of the PostProcessor as follows:
    <!-- overrides for Spring Data JPA - avoids creation of post processors by Spring Data (see JpaRepositoryConfigDefinitionParser) -->
    <bean id="org.springframework.dao.annotation.Persistence ExceptionTranslationPostProcessor#0" class="java.lang.String" />
    <bean id="org.springframework.orm.jpa.support.Persistenc eAnnotationBeanPostProcessor#0" class="java.lang.String" />

    Is there a better way to turn off the PostProcessor or should we create a JIRA-ticket for that?

    -Dominik

  • #2
    Please use [ code][/code ] tags when posting code that way it is better readable.

    Also these beans are registered by Spring when using context:component-scan or context:annotation-config. Next to that there is no (easy) way to disable the autoregistration of these beans as in general when using annotation driven configuration you want to inject an EntityManager into the beans and you also want exceptions to be translated to springs DataAccessException hierarchy.

    Why do you want to disable autoregistration of these beans? Is there a problem when they are there?

    Comment


    • #3
      We have indeed some problems when we use the post processors. I took a look at the bean registration and the PersistenceAnnotationBeanPostProcessor is registered with the name "org.springframework.context.annotation.internalPe rsistenceAnnotationProcessor" when using context:component-scan or context:annotation-config, but the PersistenceExceptionTranslationPostProcessor is not registered automatically.

      As Spring Data JPA looks for a bean named "org.springframework.orm.jpa.support.PersistenceAn notationBeanPostProcessor#0", we decided to register a dummy bean with this name to avoid the duplicate registration, because we didn't found an other way to do this. I do not think that the duplicate registration causes errors - but we nevertheless tried to avoid it. The real problem occurs with the PersistenceExceptionTranslationPostProcessor.

      In our spring configuration we define some LocalContainerEntityManagerFactoryBeans (which implement the Interface PersistenceExceptionTranslator by default). They use a specific PersistenceProvider for setting up a Hibernate Ejb3Configuration which is used for creating the EntityManagerFactory. The Ejb3Configuration also references some Hibernate Event Listener Beans, which themselve contain other beans and so on. Now - when the PersistenceExceptionTranslationPostProcessor gets instantiated, all dependencies mentioned here get also instantiated. This causes that in all of these beans AOP auto-proxying is not possible. As we need to proxy some of these beans, we can not use the post processor and register a PersistenceExceptionTranslationInterceptor manually. The interceptor is invoked on a later step in the bean registration process and therefore causes no problems (because the bean post processor for auto-proxying is already registered at this time). So we also want to avoid the automatic registration of this post processor by Spring Data JPA.

      Comment

      Working...
      X