I have the following spring xml configuration:
<bean id="entityManagerFactory1" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:/astra_persistence.xml" />
<property name="persistenceUnitName" value="myPersistenceUnit1" />
<property name="dataSource" ref="astraDataSource" />
<property name="jpaVendorAdapter" ref="astraJpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="entityManagerFactory2" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" primary="true">
<property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml" />
<property name="persistenceUnitName" value="myPersistenceUnit2" />
<property name="dataSource" ref="myDataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="jpaProperties">
<props>
<prop key="hibernate.physical_naming_strategy">com.mypackage.domain.jpa.model.naming.ImprovedPhysicalNamingStrategy</prop>
<prop key="hibernate.implicit_naming_strategy">org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl</prop>
</props>
</property>
<property name="packagesToScan"
value="com.mypackage" />
</bean>
In my DAO:
@PersistenceContext(unitName = "myPersistenceUnit2")
protected EntityManager myEntityManager;
And I can't set it up because of the following error:
NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined
I tried:
- primary="true" in xml config - no luck
- unitName instead of name in @PersistenceContext - no luck
How to fix it?