I recently ran into a requirement on one of my consulting assignments where I was required to include multiple EntityManagers in my application. Since I had never come across this before, I did some research and, much to my dismay, there were a lot of solutions that were either incorrect, incomplete or just didn’t work for my particular development environment.
In order to provide some clarity on the subject, I will present my complete solution to the requirement. Here are my environment parameters: Tomcat 7.0 application server with Spring 3.2.1 and Spring Data JPA 1.3.2.
The first thing the solution requires is setting up the persistence.xml file. Here is what mine looks like for this example:

xmlns="http://java.sun.com/xml/ns/persistence"
	             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	             version="1.0">
    <persistence-unit name="caPersistenceUnit">
       <properties>
          <property name="hibernate.generate_statistics" value="true" />
          <property name="hibernate.cache.use_structured_entries" value="true" />
          <property name="hibernate.show_sql" value="true" />
          <property name="hibernate.format_sql" value="true" />
          jdbc.batch_size" value="100" />
          <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
       </properties>
    </persistence-unit>
    <persistence-unit name="userPersistenceUnit">
       <non-jta-data-source>userDataSource</non-jta-data-source>
          <properties>
             <property name="hibernate.generate_statistics" value="true" />
             <property name="hibernate.cache.use_structured_entries" value="true" />
             <property name="hibernate.show_sql" value="true" />
             <property name="hibernate.format_sql" value="true" />
             jdbc.batch_size" value="100" />
             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
          </properties>
    </persistence-unit>
</persistence>

As you can see, I have defined two persistence units. Nothing really special here except that I needed to define the second persistence unit as a non-JTA datasource. Though you commonly deal with distributed transactions when doing enterprise application development, they were not a factor here. Consequently, I did not need a JTA datasource. Please note that the datasource should be defined in your data configuration file. This is extremely important because it will not work if don’t do that.
Speaking of the spring data configuration file, here is my sample configuration file:

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
     <jee:<span class="hiddenSpellError">jndi-lookup id="caDataSource" jndi-name="java:comp/env/jdbc/cadata"/>
     <jee:<span class="hiddenSpellError">jndi-lookup id="userDataSource" jndi-name="java:comp/env/jdbc/userdata"/>
     <context:<span class="hiddenSpellError">annotation-config />
     <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager" >
        <property name="persistenceXmlLocations">
            <list value-type="java.lang.String">
                classpath*:META-INF/persistence.xml
            </list>
        </property>
        <property name="dataSources">
            <map>
                <entry key="caDataSource" value-ref="caDataSource" />
                <entry key="userDataSource" value-ref="userDataSource" />
            </map>
        </property>
        <property name="defaultDataSource" ref="caDataSource" />
        <property name="defaultPersistenceUnitRootLocation" value="caPersistenceUnit"/>
     <!--<span class="hiddenSpellError" pre=""-->bean>
     <!-- Create the <span class="hiddenSpellError" pre="the ">JPA</span> EntityManagerFactory -->
     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="caPersistenceUnit" />
        <property name="persistenceUnitManager" ref="persistenceUnitManager" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            <!--<span class="hiddenSpellError" pre=""-->bean>
        </property>
     <!--<span class="hiddenSpellError" pre=""-->bean>
     <!-- Create the <span class="hiddenSpellError" pre="the ">JPA</span> EntityManagerFactory -->
     <bean id="userEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="userPersistenceUnit" />
        <property name="persistenceUnitManager" ref="persistenceUnitManager" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
            </bean>
        </property>
     </bean>
     <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
     </bean>
     <bean id="userTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="userEntityManagerFactory" />
     </bean>
     <jpa:repositories base-package="com.repository"
                        entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
     <jpa:repositories base-package="com.user.repository"
                      entity-manager-factory-ref="userEntityManagerFactory" transaction-manager-ref="userTransactionManager"/>
</beans>


I have defined two entity managers, two transaction managers and a persistent unit manager using the two persistence units I defined in persistence.xml file. Everything seems pretty standard except the part that I saw was missing in several of the examples I saw:

<jpa:repositories base-package="com.repository"
                        entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
<jpa:repositories base-package="com.user.repository"
                      entity-manager-factory-ref="userEntityManagerFactory" transaction-manager-ref="userTransactionManager"/>

I found that if you are missing this, even if you do EVERYTHING else correctly and it appears to work, it actually does not work!
Now that you have everything configured properly, here comes the easy part. Just pick your model objects and see which model is going to read/write to which persistence unit and database.

@PersistenceContext(unitName="caPersistenceUnit")
private EntityManager entityManager;
@PersistenceContext(unitName="userPersistenceUnit")
private EntityManager entityManager;

Make sure you use PersistenceContext instead of PersistenceUnit. I’m not 100% sure why PersistenceUnit wouldn’t work, but since I didn’t have time to dive in deeper to figure out why, instead leaving it like it was.
Well there you have it, a simple way for your application to access multiple databases using JPA. I found it simple and easy to understand. Hopefully now you have a COMPLETE way of doing this for your application if this requirement is necessary.