title: How to configure JPA multiple persistence unit in SOA
body: <p>I am using SOA and have multiple persistence.xml (each component dependent on DB). I am using Spring + JPA. Code sample as below:</p>
  
  <p>In Core:</p>
  
  <pre><code>Code:
  public abstract class GenericJpaDAOImpl&lt;T extends BaseEntity&gt; implements GenericJpaDAO&lt;T&gt; {
      protected abstract EntityManager getEntityManager();
  }
  </code></pre>
  
  <p>In Component SSO:</p>
  
  <pre><code>Code:
  public class UserDAOImpl extends GenericJpaDAOImpl&lt;User&gt; implements UserDAO {
      /* Any method specific to UserLogin */
      @PersistenceContext(unitName = "sso", type = PersistenceContextType.TRANSACTION)
      protected EntityManager entityManager;
  
      @Override
      protected EntityManager getEntityManager() {
          return this.entityManager;
      }
  }
  </code></pre>
  
  <p>Persistence.xml</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;persistence-unit name="sso" transaction-type="RESOURCE_LOCAL"&gt;
  </code></pre>
  
  <p>Application XML</p>
  
  <pre><code>Code:
      &lt;tx:annotation-driven  transaction-manager="transactionManager"/&gt;
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" &gt;
          &lt;property name="dataSource" ref="ssoDataSource" /&gt;
      &lt;property  name="persistenceUnitName" value="sso"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="ssoDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
          &lt;property name="driverClass" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="jdbcUrl" value="&lt;URL&gt;"/&gt;
          &lt;property name="user" value="&lt;USER&gt;"/&gt;
          &lt;property name="password" value="&lt;PASSWORD&gt;"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Similarlly Component: Billing (as Above)</p>
  
  <p>I got similar thread on <a href="http://forum.springsource.org/showth...sistence-units" rel="nofollow">http://forum.springsource.org/showth...sistence-units</a> but this does work for expected behaviour. In my case If application context xml for Billing gets loaded first DAO operations works file for this component but SSO component does not work. Please suggest and let me know if more detail is required. </p>