3 Replies Latest reply on Dec 20, 2007 8:06 AM by pmuir

    hbm2ddl and multiple datasources

    dennisrjohn

      I have an app that uses a mysql database for all of it's data, and when one particular event happens, needs to update a table in a MS Sql Server database. I'm using the following persistence.xml file:

      [code[
      <persistence-unit name="customerservice" transaction-type="JTA">
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>java:/customerserviceDatasource</jta-data-source>







      </persistence-unit>

      <persistence-unit name="stoneedge" transaction-type="JTA">
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>java:/stoneedgeDatasource</jta-data-source>







      </persistence-unit>

      Since the Mysql database is my app's database, I want to create-drop the tables, but the other app isn't mine, therefore, I want to validate only.

      I have entity classes defined like follows:

      @Entity
      @PersistenceUnit(unitName="customerservice")
      @DiscriminatorValue("5")
      public class TransferInteraction extends CustomerInteraction implements
       Serializable {
      
       private String transferDestination;
      
       @Length(max = 50)
       public String getTransferDestination()
       {
       return transferDestination;
       }
      
       public void setTransferDestination(String transferDestination)
       {
       this.transferDestination = transferDestination;
       }
      
       @Override
       public String toString()
       {
       return "Transfer";
       }
      
      }
      


        • 1. Re: hbm2ddl and multiple datasources
          dennisrjohn

          Sorry, typo in the persistence.xml, here;s the real thing:

          
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- Persistence deployment descriptor for dev profile -->
          <persistence 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="customerservice" transaction-type="JTA">
           <provider>org.hibernate.ejb.HibernatePersistence</provider>
           <jta-data-source>java:/customerserviceDatasource</jta-data-source>
           <properties>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
           <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
           <property name="hibernate.show_sql" value="true"/>
           <property name="hibernate.format_sql" value="true"/>
           <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
           </properties>
           </persistence-unit>
          
           <persistence-unit name="stoneedge" transaction-type="JTA">
           <provider>org.hibernate.ejb.HibernatePersistence</provider>
           <jta-data-source>java:/stoneedgeDatasource</jta-data-source>
           <properties>
           <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
           <property name="hibernate.hbm2ddl.auto" value="validate"/>
           <property name="hibernate.show_sql" value="true"/>
           <property name="hibernate.format_sql" value="true"/>
           <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
           </properties>
           </persistence-unit>
          
          </persistence>
          


          • 2. Re: hbm2ddl and multiple datasources
            dennisrjohn

            Also, I forgot to include the entity manager definitions in my pervious post:

            components.xml:

             <persistence:managed-persistence-context name="entityManager"
             auto-create="true"
             entity-manager-factory="#{customerserviceEntityManagerFactory}"/>
            
             <persistence:entity-manager-factory name="customerserviceEntityManagerFactory"
             persistence-unit-name="customerservice"/>
            
             <persistence:managed-persistence-context name="stoneEdgeEntityManager"
             auto-create="true"
             entity-manager-factory="#{stoneedgeEntityManagerFactory}"/>
            
             <persistence:entity-manager-factory name="stoneedgeEntityManagerFactory"
             persistence-unit-name="stoneedge"/>
            
            


            • 3. Re: hbm2ddl and multiple datasources
              pmuir

              What is your question?