Hi,
I have spent all day reading forums, blogs and documentation on this topic without any luck. What I want to do is:
- I have a PostgreSQL database and an SQL Server database
- I have two separate persistence.xml files (different filenames), and two entityManagerFactory beans defined:
- I have two DAO objects. In the first I use:Code:<context:load-time-weaver/> <context:annotation-config/> <tx:annotation-driven/> <tx:jta-transaction-manager /> <bean id="webCicoEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="WebCicoPU"/> <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter" p:databasePlatform="oracle.toplink.essentials.platform.database.PostgreSQLPlatform" p:showSql="false" /> </property> </bean> <bean id="centralDataEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="CentralDataPU"/> <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-CentralDataPU.xml"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter" p:databasePlatform="oracle.toplink.essentials.platform.database.SQLServerPlatform" p:showSql="false" /> </property> </bean>
in the second I use:Code:@PersistenceContext(name = "WebCicoPU") private transient EntityManager entityManager;
Notice that there is no mention of datasource. Spring automatically picks it up from the persistence.xml (JNDI). JPA+JTA work fine when using just a single persistence unit but now that I need to use two, I get the following exception:Code:@PersistenceContext(name = "CentralDataPU") private transient EntityManager entityManager;
Spring gives the following exception:
Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
How do I tell which entity manager factory to use per DAO object?
This thread did not help:
http://forum.springframework.org/sho...d+single+found
Thanks,
Ryan


Reply With Quote