I need some help to configure several connection's to multiple db's using the same Persistence unit.
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:
<persistence-unit name="PersistenceUnit-c1" transaction-type="RESOURCE_LOCAL"> <properties> <property name="hibernate.show_sql" value="${hibernate-show-sql}"/> <property name="hibernate.dialect" value="org.hibernate.dialect.SybaseDialect" /> <property name="hibernate.c3p0.min_size" value="${hibernate-c3p0-min-size}" /> <property name="hibernate.c3p0.max_size" value="${hibernate-c3p0-max-size}" /> <property name="hibernate.c3p0.timeout" value="${hibernate-c3p0-timeout}" /> <property name="hibernate.c3p0.max_statements" value="${hibernate-c3p0-max-statements}" /> <property name="hibernate.c3p0.idle_test_period" value="${hibernate-c3p0-idle-test-periods}" /> </properties>
<class>com.domain.TktOrder</class>
<exclude-unlisted-classes/>
</persistence-unit>
I am also using Spring/hibernate to set up my context:
<bean id="EntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceUnitName="PersistenceUnit-c1"
p:dataSource-ref="DataSource">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="${hibernate-show-sql}"
p:generateDdl="false"
p:databasePlatform="org.hibernate.dialect.SybaseDialect" />
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<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"
/>
and finally I use:
@PersistenceContext(unitName="PersistenceUnit-c1")
public void setEntityManager(EntityManager entityManager)
{
this.entityManager = entityManager;
}
to inject my EntityManager into my DAO
How can I extend this model to be able to use db1 then change the data source and execute again for db2 etc?
Many thanks for any help in advance!