2 Replies Latest reply on May 8, 2006 11:36 AM by cyril.joui

    How to work with 2 databases simultaneously?

    keithahern

      I can't tell this is a bug in JBoss or I'm using EJB3 incorrectly.

      I can create 2 persistence units with out a problem.

      My session means are injected with a entitymanager associcated with the appropriate unitname of the persistence unit, so far so good.

      But, entity means seem to have no allegiance with a particular persistence unit, I can't see how to tie them together, the @PersistenceContext unitname at class level is having no effect.

      What happens is all the entitybeans are created in all databases with a persistence context setting of


      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>


      To summarize, I'm trying to keep two databases apart but the schemas are polluting each other.

      How do I prevent this at the entity bean level?



        • 1. Re: How to work with 2 databases simultaneously?
          keithahern

          bump, surely there are people out there working with 2 databases? In my cases its adapting a legacy database to work with a new architecture.

          How do I assign an entity bean to a database?

          • 2. Re: How to work with 2 databases simultaneously?

            Hello,

            It's totally possible.
            Here is an example :

            <?xml version="1.0"?>
            <persistence version="1.0">
            
             <persistence-unit name="transactionUP">
             <jta-data-source>java:Stock1DS</jta-data-source>
             <provider>org.hibernate.ejb.HibernatePersistence</provider>
             <class>com.labosun.stockmanager.entity.Transaction</class>
             <properties>
             <property name="hibernate.hbm2ddl.auto" value="create-drop" />
             <property name="hibernate.dialect"
             value="org.hibernate.dialect.MySQLInnoDBDialect" />
             </properties>
             <exclude-unlisted-classes />
             </persistence-unit>
            
             <persistence-unit name="stockmanagerUP">
             <jta-data-source>java:Stock2DS</jta-data-source>
             <provider>org.hibernate.ejb.HibernatePersistence</provider>
             <class>com.labosun.stockmanager.entity.FinancialProduct</class>
             <class>com.labosun.stockmanager.entity.Bond</class>
             <class>com.labosun.stockmanager.entity.Portfolio</class>
             <class>com.labosun.stockmanager.entity.Stock</class>
             <class>com.labosun.stockmanager.entity.Portfolio</class>
             <class>com.labosun.stockmanager.entity.User</class>
             <class>com.labosun.stockmanager.entity.AccountInfo</class>
             <class>com.labosun.stockmanager.entity.Address</class>
             <properties>
             <property name="hibernate.hbm2ddl.auto" value="create-drop" />
             <property name="hibernate.dialect"
             value="org.hibernate.dialect.MySQLInnoDBDialect" />
             </properties>
             <exclude-unlisted-classes />
             </persistence-unit>
            
            </persistence>
            


            Don't hesitate to ask for questions.

            Good luck.