title: Reading from multiple Db's with same Persistence Unit?
body: <p>I need some help to configure several connection's to multiple db's using the same Persistence unit. </p>
  
  <p>They all have the same schema. Therefore I want to use the same Persistence unit/ DAO's etc and dont want to have to setup 10 EntityManagers, 10 Persistence xml's etc. Is there a way to do this? Here is my current config:</p>
  
  <blockquote>
  <pre><code>  &lt;persistence-unit name="PersistenceUnit-c1" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.show_sql" value="${hibernate-show-sql}"/&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.SybaseDialect" /&gt;
              &lt;property name="hibernate.c3p0.min_size" value="${hibernate-c3p0-min-size}" /&gt;
              &lt;property name="hibernate.c3p0.max_size" value="${hibernate-c3p0-max-size}" /&gt;
              &lt;property name="hibernate.c3p0.timeout" value="${hibernate-c3p0-timeout}" /&gt;
              &lt;property name="hibernate.c3p0.max_statements" value="${hibernate-c3p0-max-statements}" /&gt;
              &lt;property name="hibernate.c3p0.idle_test_period" value="${hibernate-c3p0-idle-test-periods}" /&gt;     
          &lt;/properties&gt;
  </code></pre>
  </blockquote>
  
  <pre><code>        &lt;class&gt;com.domain.TktOrder&lt;/class&gt;
          &lt;exclude-unlisted-classes/&gt;
      &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>I am also using Spring/hibernate to set up my context:</p>
  
  <pre><code>    &lt;bean id="EntityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      p:persistenceUnitName="PersistenceUnit-c1" 
      p:dataSource-ref="DataSource"&gt;
      &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
              p:showSql="${hibernate-show-sql}" 
              p:generateDdl="false" 
              p:databasePlatform="org.hibernate.dialect.SybaseDialect" /&gt;
      &lt;/property&gt;
      &lt;property name="loadTimeWeaver"&gt;
          &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="DataSource" 
      class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" 
      p:driverClass="net.sourceforge.jtds.jdbc.Driver"
      p:jdbcUrl="jdbc:jtds:sybase://url.net:port;DatabaseName=db_1"
      p:user="user" 
      p:password="password"
      /&gt;
  </code></pre>
  
  <p>and finally I use: </p>
  
  <pre><code>@PersistenceContext(unitName="PersistenceUnit-c1")
  public void setEntityManager(EntityManager entityManager)
  {
      this.entityManager = entityManager;     
  
  }
  </code></pre>
  
  <p>to inject my EntityManager into my DAO</p>
  
  <p>How can I extend this model to be able to use db1 then change the data source and execute again for db2 etc?</p>
  
  <p>Many thanks for any help in advance!</p>