1 Reply Latest reply on Apr 28, 2009 5:41 AM by Adrian Brock

    datasource from log4j appender

    Jonathan Tougas Newbie

      I've got an issue getting connections from a data source from a log4j appender.
      The appender is configured to use the same data source as the application, and when code from a @PreDestroy EJB method writes to log4j, this error occurs in the appender.

      org.jboss.util.NestedSQLException:
      Transaction is not active: tx=TransactionImple < ac, BasicAction: -53efa2b4:11e1:49f5f5da:70 status: ActionStatus.COMMITTED >;
      - nested throwable: (javax.resource.ResourceException:
      Transaction is not active: tx=TransactionImple < ac, BasicAction: -53efa2b4:11e1:49f5f5da:70 status: ActionStatus.COMMITTED >)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)
      at ca.company.foo.log.DSConnectionHandler.getConnection(DSConnectionHandler.java:34)
      at org.apache.log4j.jdbcplus.JDBCLogger.prepareConnection(JDBCLogger.java:489)
      at org.apache.log4j.jdbcplus.JDBCLogger.append(JDBCLogger.java:555)
      at org.apache.log4j.jdbcplus.JDBCAppender.flush_buffer(JDBCAppender.java:887)
      at org.apache.log4j.jdbcplus.JDBCAppender.append(JDBCAppender.java:867)
      [snip]
      


      I'm expecting to get a connection back from the data source that I can use in autocommit mode (write the log to the database and return the connection to the pool)

      Here is the data source definition, nothing fancy
       <local-tx-datasource>
       <jndi-name>scnDatasource</jndi-name>
       <connection-url>jdbc:oracle:thin:@cps-test-1:1521:CPSDEV</connection-url>
       <driver-class>oracle.jdbc.OracleDriver</driver-class>
       <user-name>test</user-name>
       <password>test</password>
       </local-tx-datasource>
      


      Creating a copy of the data source, changing "local-tx-datasource" to "no-tx-datasource" makes the problem go away, but I'd rather use the same data source. I guess there's something I'm missing or not understanding. Are data sources supposed to be shareable like this?

      I'm using jboss-5.0.0.GA + jboss-seam-2.1.1.GA

      Cheers!

        • 1. Re: datasource from log4j appender
          Adrian Brock Master

          You can't use the local-tx-datasource because it will inherit the transaction from the ejb context.

          In the stacktrace you show, the jta tranaction has already been aborted so it can't log
          (write things into the database).

          Even If it wasn't already aborted, a subsequent rollback of the transaction would mean
          nothing gets logged.

          Also, you certainly can't set auto commit to false on a transactional
          datasource that is enlisted in a transaction like you have.