Description
Baruch Sadogursky opened SPR-7387 and commented
This is clear Single responsibility principle violation.
The implementation logic of PersistenceExceptionTranslator resides into various FactoryBeans (LocalSessionFactoryBean, LocalEntityManagerFactoryBean, etc) and there is no way to introduce translators to ApplicationContext for PersistenceExeptionTranslationPostProcessor to find them without adding the FactoryBeans to ApplicationContext.
It works fine for xml metadata, since we add the FactoryBeans to the context anyway.
This is not the case when working with Java @Configuration
classes. In them we don't expose FactoryBeans to ApplicationContext, but use them internally in @Bean
methods, returning only the result of the getObject() call. This way there are no PersistenceExceptionTranslators in the ApplicationContext and PersistenceExeptionTranslationPostProcessor fails.
Affects: 3.0.3
Attachments:
- HibernateExceptionTranslator.java (3.69 kB)
Issue Links:
- Provide alternatives to using FactoryBean types within @Bean methods [SPR-7418] #12076 Provide alternatives to using FactoryBean types within
@Bean
methods ("is superseded by")
Referenced from: commits 3bb01ee