Announcement Announcement Module
Collapse
No announcement yet.
Best way to add multiple entity manager factory in applicationContext.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best way to add multiple entity manager factory in applicationContext.xml

    Hello Everyone,

    I am using Spring 2.5, JBoss5.0, JPA and Hibernate3

    Right now I am using only one entityManagerFactory and one dataSource. But due to complexity of the application and due to corporate decisions there will be three databases. I work for an insurance company. There are three databases "insureDB1","insureDB2","insureDB3". But the funny thing is all the database table names and their structure is exactly same, they just hold different information. But there might be some cases where insureDB1 might have 3 more tables and insureDB3 might have 5 less tables so I dont know if I can use the same persistence unit or not

    Here is the sample code from my applicationContext.xml:
    <bean
    class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />

    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="database" value="INFORMIX" />
    <property name="showSql" value="true" />
    </bean>
    </property>
    </bean>

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="com.informix.jdbc.IfxDriver" />
    <property name="url"
    value="jdbc:informix-sqli://192.168.3.138:1526/insureDB1:INFORMIXSERVER=ol_ids_1;DELIMIDENT=y;" />
    <property name="username" value="username" />
    <property name="password" value="password" />
    </bean>

    I have defined a persitence.xml under META-INF which is being picked up by application automatically.

    In the DAO I am using annotations like this:
    @PersistenceContext
    public void setEntityManager(EntityManager em) {
    this.em = em;
    }

    private EntityManager getEntityManager() {
    return em;
    }

    Please give your suggestion how should I add the additional dataSource and entitymanagerFactory and persistence.xml so that I can use the additional databases just by adding addtional entries in applicationContext.xml. For example if want to access the two entityManagers in the same DAO how that could be achieved?

    I would really appreciate any suggestion on this issue.
Working...
X