2 Replies Latest reply on Jan 29, 2009 3:18 PM by allapetrova

    How to configure XA Datasource for JBoss 4.2.2 and Postgres?

      I am on JBoss 4.2.2 and I need to configure XA Datasource for Postgres.
      Here is exempt from my postgres-ds.xml


      <datasources>
       <xa-datasource>
       <jndi-name>DefaultDS</jndi-name>
       <connection-url>jdbc:postgresql://some_url/ecommdb</connection-url>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>some_name</user-name>
       <password>foo</password>
      
       <!-- sql to call when connection is created -->
       <new-connection-sql>select count(*) from status</new-connection-sql>
      
       <!-- sql to call on an existing pooled connection when it is obtained from pool -->
       <check-valid-connection-sql>select count(*) from status</check-valid-connection-sql>
      
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
       <metadata>
       <type-mapping>PostgreSQL 7.2</type-mapping>
       </metadata>
       </xa-datasource>
      ......
      </datasources>




      But when I try connecting to this database I get the following exception:


      Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: No XADataSourceClass supplied!)
      at org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory.createManagedConnection(XAManagedConnectionFactory.java:144)
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:577)
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:262)
      at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:500)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:341)
      at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:315)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:396)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
      ... 84 more



      What did I miss?
      Thanks in advance for any help you can give.

        • 1. Re: How to configure XA Datasource for JBoss 4.2.2 and Postg

          Ok, I figured it out and documenting for those who come later. Below is an example of XA Datasource configuration for Postgres: postgres-xa-ds.xml
          Also you need to have Postgress .jar with org.postgresql.xa.PGXADataSource in your JBoss classpath. I am using postgresql-8.3-604.jdbc3.jar. I put it in my application lib directory.

          The database I am connecting to is legacy version 7.2 So I am not sure if I would have any problems with it, but it is a separate issue.

          <datasources>
           <xa-datasource>
           <jndi-name>DefaultDS</jndi-name>
           <track-connection-by-tx/>
           <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
           <xa-datasource-property name="ServerName">MyTestDBServer</xa-datasource-property>
           <xa-datasource-property name="DatabaseName">MyDBName</xa-datasource-property>
           <user-name>X</user-name>
           <password>Y</password>
           <!-- sql to call when connection is created -->
           <new-connection-sql>select count(*) from pd_status</new-connection-sql>
          
           <!-- sql to call on an existing pooled connection when it is obtained from pool -->
           <check-valid-connection-sql>select count(*) from pd_status</check-valid-connection-sql>
          
           <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
           <metadata>
           <type-mapping>PostgreSQL 7.2</type-mapping>
           </metadata>
           </xa-datasource>
          
          .....
          
          </datasources>