4 Replies Latest reply on Jul 4, 2012 9:57 AM by wdfink

    xa-datasource x creating tables in both database

    lucianoborges

      Hi all,

       

      I'm trying create a two-phase commit application, but, when the JBoss starts the app creates the table on both databases.

       

      My -ds.xml

       

      <datasources>
         <xa-datasource>
           <jndi-name>PostgreSQLXA1</jndi-name>
           <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
           <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
           <xa-datasource-property name="PortNumber">5432</xa-datasource-property>
           <xa-datasource-property name="DatabaseName">bd1</xa-datasource-property>
           <xa-datasource-property name="User">postgres</xa-datasource-property>
           <xa-datasource-property name="Password">postgres</xa-datasource-property>
           <track-connection-by-tx></track-connection-by-tx>
         </xa-datasource>
         <xa-datasource>
           <jndi-name>PostgreSQLXA2</jndi-name>
           <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
           <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
           <xa-datasource-property name="PortNumber">5432</xa-datasource-property>
           <xa-datasource-property name="DatabaseName">bd2</xa-datasource-property>
           <xa-datasource-property name="User">postgres</xa-datasource-property>
           <xa-datasource-property name="Password">postgres</xa-datasource-property>
           <track-connection-by-tx></track-connection-by-tx>
         </xa-datasource>
      </datasources>
      
      

       

      My persistence.xml

       

      <persistence-unit name="database1-ds" transaction-type="JTA">
           <jta-data-source>java:/PostgreSQLXA1</jta-data-source>
                <class>example.twophasecommit.domain.Book</class>
                <properties>
                     <property name="hibernate.show_sql" value="true" />
                     <property name="hibernate.format_sql" value="false" />
                     <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                     <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                </properties>
      </persistence-unit>
      
      <persistence-unit name="database1-ds" transaction-type="JTA">
           <jta-data-source>java:/PostgreSQLXA2</jta-data-source>
                <class>example.twophasecommit.domain.BookSummary</class>
                <properties>
                     <property name="hibernate.show_sql" value="true" />
                     <property name="hibernate.format_sql" value="false" />
                     <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                     <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                </properties>
      </persistence-unit>
      

       

      Is there something wrong?

       

      Thanks,

      Luciano

        • 1. Re: xa-datasource x creating tables in both database
          wdfink

          How your deployment archive structure is?

          Also the JBoss version might be helpful.

          • 2. Re: xa-datasource x creating tables in both database
            lucianoborges

            Hi Wolf.

             

            My war look like this:

             

            twophasecommit.war

            `-- WEB-INF

                |-- classes

                |   |-- example

                |   |   `-- twophasecommit

                |   |       |-- entity

                |   |       |   |-- Book.class

                |   |       |   `-- BookSummary.class

                |   |       `-- persistence

                |   |           |-- BookDAO.class

                |   |           `-- BookSummaryDAO.class

                |   |-- META-INF

                |   |   `-- persistence.xml

                |-- lib

                |  

                `-- web.xml

             

            My JBoss is 6.0.

             

            My entities:

             

            package example.twophasecommit.domain;

            import java.io.Serializable;

            import javax.persistence.Column;

            import javax.persistence.Entity;

            import javax.persistence.GeneratedValue;

            import javax.persistence.Id;

             

            @Entity

            public class Book implements Serializable {

             

            private static final long serialVersionUID = 1L;

             

                      @Id

                      @GeneratedValue

                      private Long id;

             

                      @Column

                      private String title;

             

                      @Column

                      private String author;

             

                      public Book() {

                                super();

                      }

             

                      public Book(String title, String author) {

                                this.title = title;

                                this.author = author;

                      }

             

                      public Long getId() {

                                return id;

                      }

             

                      public void setId(Long id) {

                                this.id = id;

                      }

             

              public String getTitle() {

                                return title;

                      }

             

                      public void setTitle(String title) {

                                this.title = title;

                      }

             

                      public String getAuthor() {

                                return author;

                      }

             

                      public void setAuthor(String author) {

                                this.author = author;

                      }

            }

            ---------------

            package example.twophasecommit.domain;

            import java.io.Serializable;

            import javax.persistence.Entity;

            import javax.persistence.Id;

             

            @Entity

            public class BookSummary implements Serializable{

             

                      private static final long serialVersionUID = 1L;

             

                      @Id

                      private int id;

             

                      private String summary;

             

                      public String getSummary() {

                                return summary;

                      }

             

                      public void setSummary(String summary) {

                                this.summary = summary;

                      }

             

                      public void setId(int id) {

                                this.id = id;

                      }

             

                      public int getId() {

                                return id;

                      }

             

            }

             

            Thanks,

            Luciano

            • 3. Re: xa-datasource x creating tables in both database
              lucianoborges

              Hi Wolf,

               

              I found my error. We have to insert the tag <exclude-unlisted-classes>true</exclude-unlisted-classes> in the persistence.xml.

               

              Thanks,

              Luciano

              • 4. Re: xa-datasource x creating tables in both database
                wdfink

                Yep, that was my idea if I see your structure

                 

                Sometimes it helps if you explain your problem to someone