PDA

View Full Version : How can use multiple persistence-unit with spring data jpa



nazeer
Jul 29th, 2011, 11:19 AM
I am using

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.0.0.M1</version>
</dependency>

I want to know how to tell <jpa:repositories> to use SharedEntityManagerBean?
I have multiple jar's with different persistence units
and at the time of autowire repo's it would fail saying "No unique bean EntityManagerFactory" : Exception given below
------------------------------------------------
org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findDefaultEntityManagerF actory(PersistenceAnnotationBeanPostProcessor.java :536)
at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findEntityManagerFactory( PersistenceAnnotationBeanPostProcessor.java:495)

Oliver Gierke
Aug 23rd, 2011, 02:19 AM
There's an entity-manager-factory-ref attribute at the repositories element that allows you to explicitly wire the EMF to all repositories discovered by that element to work with. Unfortunately the documentation doesn't seem to mention that attribute so I created DATADOC-91 [0].

[0] https://jira.springsource.org/browse/DATAJPA-91