3

I am using Spring Data Jpa version 1.0.0.M2 here is the url: http://static.springsource.org/spring-data/data-jpa/docs/1.0.0.M2/reference/pdf/spring-data-jpa-reference.pdf

All is promised to be very simple and nice, but when it comes to two datasources it breaks down. The question is how to setup with two data sources? The JpaRepository automatically searches for EntityManager, when it finds more than two it throws exceptions.

If you have any idea with EntityManager and how to setup the spring data jpa, please post a reply. Your help is truly appreciated!!!

abalogh
  • 8,239
  • 2
  • 34
  • 49
truthseeker
  • 439
  • 1
  • 5
  • 9
  • 1
    I think this was answered in a similar question, have a look: http://stackoverflow.com/a/12630799/229178 – sbzoom Oct 10 '12 at 14:43

3 Answers3

7
<jpa:repositories base-package="org.springframework.data.jpa.repository.sample"
    entity-manager-factory-ref="secondEntityManagerFactory" />
Leonid
  • 184
  • 4
1

You can use a dynamic datasource that wrap your two datasources, as explained here:

http://blog.springsource.com/2007/01/23/dynamic-datasource-routing/

Vincent Devillers
  • 1,628
  • 1
  • 11
  • 17
0

Are you looking to use 'EntityManager-A' with Spring Data JPA and 'EntityManager-B' for another data access layer? Mark

  • 1
    I have found the solution to this, from another post (I forgot what it was, might be Oliver's post), that you can set entity-manager-factory-ref and transaction-manager-ref in spring-data-jpa repositories, so after setting the jpa persistence properties and multiple entity-managers, everything is configured nicely. – truthseeker May 31 '11 at 12:54
  • If that's the case you might want to accept Leonid's answer as a valid one :). – Oliver Drotbohm Jul 04 '11 at 12:21