Hi all. I'm working through a problem using two entity managers, with two distinct data sources and underlying schemas. I'm currently using Spring 3.1.2.RELEASE with Spring-Data 1.1.2.RELEASE.
As you will be able to tell by contents of the application context, I have two separate modules... each in charge of their respective database objects and repository implementations. My base application uses each of these modules to communicate with their respective database schemas. Further detail:
Application context:
I have two relevant interfaces:HTML Code:<tx:annotation-driven /> <jdbc:embedded-database id="clientdb" /> <jpa:repositories base-package="....data.client" entity-manager-factory-ref="clientEmf" transaction-manager-ref="clientTxManager"/> <bean id="clientEmf" name="clientEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="clientdb" /> <property name="packagesToScan" value="....data.client.dbo" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="HSQL" /> </bean> </property> <qualifier value="clientEmf"/> </bean> <bean id="clientTxManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="clientEmf" /> </bean> <bean id="clientDataContext" class="....ClientDataContext"> <constructor-arg> <ref bean="clientdb" /> </constructor-arg> </bean> <jpa:repositories base-package="....data.admin" entity-manager-factory-ref="adminEmf" transaction-manager-ref="adminTxManager"/> <jdbc:embedded-database id="admindb" /> <bean id="adminEmf" name="adminEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="admindb" /> <property name="packagesToScan" value="....data.admin.dbo" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="HSQL" /> </bean> </property> <qualifier value="adminEmf"/> </bean> <bean id="adminTxManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="adminEmf" /> </bean> <bean id="adminDataContext" class="....data.admin.api.AdminDataContext"> <constructor-arg> <ref bean="admindb" /> </constructor-arg> </bean>
andCode:public interface StuffRepositoryCustom { public List<Stuff> getStuff(); }
Code:public interface StuffRepository extends JpaRepository<Stuff, Integer>, QueryDslPredicateExecutor<Stuff>, StuffRepositoryCustom { }
and then my implementing class:
Code:@Repository public class StuffRepositoryImpl implements StuffRepositoryCustom{ EntityManager entityManager; @PersistenceContext(name="clientEmf") public void setEntityManager(EntityManager em) { entityManager = em; } public List<Stuff> getStuff(){ ... some implementation } }
My problem is that the wiring of the entity manager does not seem to be happening correctly. The root of the exception thrown is:
So, my question is, how am I to delineate these two entity managers for use within the application? If I am interpreting the spring source documentation correctly here, entity-manager-factory-ref should have handled which entity manager gets directed to each of the contained subclasses. However, that does not seem to work as I expect.Code:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
If I can provide any more information to help, please let me know! I've been working on this for a couple of days now to no avail. Thanks in advance!


Reply With Quote
