this should do the trick...
in your applicationcontext-jdbc.xml or similarly purposed configuration file
you should have a similar situation
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:orcl="http://www.springframework.org/schema/data/orcl"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/data/orcl
http://www.springframework.org/schema/data/orcl/spring-data-orcl-1.0.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Used to enable transaction annotation on the DBItaServiceImpl class -->
<!-- <bean id="cerempService" class="eu.europa.acer.aris.ceremp.service.impl.CerempServiceImpk" /> -->
<!-- Enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven />
<!-- Caching configuration -->
<cache:annotation-driven />
<!-- ehcache Cache Manager -->
<bean class="org.springframework.cache.ehcache.EhCacheCacheManager" id="cacheManager" p:cacheManager-ref="ehcache"/>
<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:configLocation="classpath:ehcache.xml" p:shared="true" />
<aop:aspectj-autoproxy/>
<!-- AOP used to debug spring-jpa -->
<bean class="org.springframework.aop.interceptor.CustomizableTraceInterceptor"
id="customizableTraceInterceptor">
<property name="enterMessage" value="Entering $[methodName]($[arguments])" />
<property name="exitMessage" value="Leaving $[methodName](): $[returnValue]" />
</bean>
<aop:config>
<aop:advisor advice-ref="customizableTraceInterceptor"
pointcut="execution(public * org.springframework.data.jpa.repository.JpaRepository+.*(..))" />
</aop:config>
<!-- Activate Spring Data JPA repository support -->
<jpa:repositories base-package="eu.europa.acer.aris.ceremp.repository" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
<jpa:repositories base-package="eu.europa.acer.aris.ceremp.iamrepository" entity-manager-factory-ref="entityManagerFactory2" transaction-manager-ref="transactionManager2"/>
<!-- <util:properties id="hibernatePropertiesProps">
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key = "hibernate.show_sql">true </prop>
<prop key="org.hibernate.envers.auditTablePrefix">AUD_</prop>
<prop key="org.hibernate.envers.auditTableSuffix"></prop>
<prop key="org.hibernate.envers.store_data_at_delete">true</prop>
</util:properties> -->
<util:properties id="hibernatePropertiesProps">
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="log4j.logger.org.hibernate.SQL">ALL</prop>
<prop key="log4j.logger.org.hibernate.type">ALL</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="org.hibernate.envers.auditTablePrefix">AUD_</prop>
<prop key="org.hibernate.envers.auditTableSuffix"></prop>
<prop key="org.hibernate.envers.store_data_at_delete">true</prop>
</util:properties>
<!-- flyway part -->
<beans profile="ci,local,dev,qa,test,smarts,prototype,pilot,testframework,testframework-lutech">
<bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate" depends-on="dataSource">
<property name="dataSource" ref="dataSource"/>
<property name="disableInitCheck" value="true" />
<property name="encoding" value="UTF-8"></property>
<property name="placeholders" ref="flyway.prop"/>
</bean>
</beans>
<beans profile="staging,preprod,prod">
<bean id="flyway" class="com.googlecode.flyway.core.Flyway">
<property name="placeholders" ref="flyway.prop"/>
</bean>
</beans>
<!-- Declare a JPA entityManagerFactory -->
<beans profile="ci,local,dev,qa,test,smarts,prototype,pilot,testframework,testframework-lutech">
<bean id="entityManagerFactory" depends-on="flyway"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceProviderClass="org.hibernate.ejb.HibernatePersistence"
p:jpaVendorAdapter-ref="hibernateVendor"
p:jpaProperties-ref="hibernatePropertiesProps"
p:dataSource-ref="dataSource"
p:persistenceUnitName="persistenceUnitDCI"
p:packagesToScan= "eu.europa.acer.aris.ceremp.domain,eu.europa.acer.aris.ceremp.auditing,eu.europa.acer.aris.ceremp.domain.readonly" >
<qualifier value ="emfDCI" />
</bean>
<bean id="entityManagerFactory2"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceProviderClass="org.hibernate.ejb.HibernatePersistence"
p:jpaVendorAdapter-ref="hibernateVendor"
p:jpaProperties-ref="hibernatePropertiesProps"
p:dataSource-ref="dataAltSource"
p:persistenceUnitName="persistenceUnitIAM"
p:packagesToScan= "eu.europa.acer.aris.ceremp.domain,eu.europa.acer.aris.ceremp.auditing,eu.europa.acer.aris.ceremp.domain.readonly" >
<qualifier value ="emfIAM" />
</bean>
</beans>
<beans profile="staging,preprod,prod">
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceProviderClass="org.hibernate.ejb.HibernatePersistence"
p:jpaVendorAdapter-ref="hibernateVendor"
p:jpaProperties-ref="hibernatePropertiesProps"
p:dataSource-ref="dataSource"
p:persistenceUnitName="persistenceUnitDCI"
p:packagesToScan= "eu.europa.acer.aris.ceremp.domain,eu.europa.acer.aris.ceremp.auditing,eu.europa.acer.aris.ceremp.domain.readonly" >
<qualifier value ="emfDCI" />
</bean>
<bean id="entityManagerFactory2"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceProviderClass="org.hibernate.ejb.HibernatePersistence"
p:jpaVendorAdapter-ref="hibernateVendor"
p:jpaProperties-ref="hibernatePropertiesProps"
p:dataSource-ref="dataAltSource"
p:persistenceUnitName="persistenceUnitIAM"
p:packagesToScan= "eu.europa.acer.aris.ceremp.domain,eu.europa.acer.aris.ceremp.auditing,eu.europa.acer.aris.ceremp.domain.readonly" >
<qualifier value ="emfIAM" />
</bean>
</beans>
<beans>
<!-- Specify our ORM vendor -->
<bean id="hibernateVendor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="false"/>
<!-- Declare a transaction manager-->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"
p:dataSource-ref="dataSource"/>
<!-- Declare a transaction manager-->
<bean id="transactionManager2"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory2"
p:dataSource-ref="dataAltSource"/>
</beans>
<!-- Define the oracle pooling datasource of spring-data which use the class oracle.jdbc.pool.OracleDataSource -->
<beans profile="local">
<orcl:pooling-datasource id="dataSource"
url="jdbc:oracle:thin:@db00-ccea.labucs.int:1521:CCEA" username="${db.credential.username}" password="${db.credential.password}"/>
<util:properties id="flyway.prop" location="classpath:config_local.properties"/>
<orcl:pooling-datasource id="dataAltSource"
url="jdbc:oracle:thin:@db00-ccea.labucs.int:1521:CCEA" username="${db2.credential.username}" password="${db2.credential.password}"/>
<util:properties id="flyway.prop" location="classpath:config_local.properties"/>
</beans>
</beans>
Now... you should have a Repository&RepositoryImpl class for that object... in the repositoryimpl class of reference have something like this:
package eu.europa.acer.aris.ceremp.iamrepository.impl;
public class UserRepositoryImpl implements UserRepositoryCustom
{
@Qualifier("emfIAM")
@Autowired
private EntityManagerFactory em;
}
Basically you have to autowire a entitymanagerfactory and specify via the qualifier the qualifer you configured for the specific entitymanagerfactory for the connection you want to use for that specific object :)
You have other alternative, but this is the easiest one, though you might consider the other as well, like defining an attribute that defines which entitymanager will be used to handled two object of the same class e.g. you have customer with customer of category gold being present in a schema and customer of category silver in a different schema alltogether...
Hope this helps :)