x
login register about faq

How to configure JPA multiple persistence unit in SOA

Hi

I am using SOA and have multiple persistence.xml (each component dependent on DB). I am using Spring + JPA. Code sample as below:

In Core:

Code:
public abstract class GenericJpaDAOImpl<T extends BaseEntity> implements GenericJpaDAO<T> {
    protected abstract EntityManager getEntityManager();
}

In Component SSO:

Code:
public class UserDAOImpl extends GenericJpaDAOImpl<User> implements UserDAO {
    /* Any method specific to UserLogin */
    @PersistenceContext(unitName = "sso", type = PersistenceContextType.TRANSACTION)
    protected EntityManager entityManager;

    @Override
    protected EntityManager getEntityManager() {
       return this.entityManager;
    }
}

Persistence.xml

Code:
<persistence-unit name="sso" transaction-type="RESOURCE_LOCAL">

Application XML

Code:
    <tx:annotation-driven  transaction-manager="transactionManager"/>
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
        <property name="dataSource" ref="ssoDataSource" />
    <property  name="persistenceUnitName" value="sso"></property>
    </bean>

    <bean id="ssoDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUrl" value="<URL>"/>
        <property name="user" value="<USER>"/>
        <property name="password" value="<PASSWORD>"/>
    </bean>

Similarlly Component: Billing (as Above)

I got similar thread on http://forum.springsource.org/showth...sistence-units 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.

more ▼

asked Aug 30 '11 at 02:40 AM

Shishir.Kumar gravatar image

Shishir.Kumar
1 3 3 4

(comments are locked)
10|600 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x28
x4
x3

asked: Aug 30 '11 at 02:40 AM

Seen: 919 times

Last Updated: Aug 30 '11 at 02:40 AM