Description
Thomas Strecker opened SPR-7549 and commented
I am generally very happay with all the magic Spring provides me. This week, however, I ran into a problem I can't seem to solve, namely having two persistence units and therefore entity manager factories in my application's context.
While everything works perfect when I declare and annotate the EntityManager in all relevant classes with the @PersistenceContext
(unitName="XYZ"), I am having a slightly different problem. While one of the persistence units' names is static (b/c I control it) the name of the other is dynamic. This may seem silly but is beyond my control.
So I tried to provide the one EMF with the "primary=true" and the other with the "primary=false" attributes, hoping that the context would inject the primary EMF into those classes where I didn't specify the name of the persistence unit, while the other classes would obtain the EMF specified through the unitName.
Unfortunately, PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory() does not check for the "primary" attribute of the retrieved beans, therefore complaining that the default entity manager cannot be obtained.
I, therefore, suggest to implement this check in the post processor.
Affects: 3.0.4
Issue Links:
- Support for Hibernate ORM 5.2 [SPR-14327] #18899 Support for Hibernate ORM 5.2
- StackOverflowError for advisor search against factory-bean reference to FactoryBean [SPR-14551] #19119 StackOverflowError for advisor search against factory-bean reference to FactoryBean
- Avoid creation of lazy candidates when the primary bean is injected [SPR-14611] #19178 Avoid creation of lazy candidates when the primary bean is injected
- SchedulingConfigurer's ScheduledTaskRegistrar should reliably shut down before TaskScheduler [SPR-15067] #19633 SchedulingConfigurer's ScheduledTaskRegistrar should reliably shut down before TaskScheduler
- Track bean dependencies for calls between @Bean methods within @Configuration classes [SPR-15069] #19635 Track bean dependencies for calls between
@Bean
methods within@Configuration
classes
1 votes, 2 watchers