Version 3

    I get an SQLException with an IO or Network Error

     

    This means the connection to the database has broken.

     

    New Connections

     

    JBoss can detect this problem when the connection is being checked out from the pool.

     

    If JBoss detects the connection is broken before it is checked out from the pool, the application does

    not see the problem. A warning is logged and JBoss chooses a different connection. It will create new connections if necessary.

     

    In use Connections

     

    However, if the connection has already been checked out from the pool and breaks while the application is using the connection, there is nothing JBoss can do about it.

     

    There is state associated with the connection inside the database that JBoss cannot recover.

     

    The only recovery possible is to propagate the exception back to the application and let it rollback the transaction. Once the transaction is rolled back, the application can retry the unit of work.

     

    SQLException

     

    SQLException is an application exception according to the EJB spec. That means it does not automatically rollback the transaction. The application must do something like the following to force a rollback:

    try
    {
       // do work
    }
    catch (SQLException e)
    {
       sessionContext.setRollbackOnly();
       throw new ApplicationException(e);
    }
    

     

    or throw a RuntimeException like EJBException.

     

    Exception Sorter

     

    JBoss has an interface called ExceptionSorter

    that can be coded to look at vendor specific error codes to decide whether an SQLException is a fatal exception that requires the connection to be closed.

    Vendor specific implementations are provided for some databases.

     

    It is configured on the datasource:

    <datasources>
      <local-tx-datasource>
        <jndi-name>OracleDS</jndi-name>
        <connection-url>jdbc:oracle:thin:@youroraclehost:1521:yoursid</connection-url>
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
        <user-name>x</user-name>
        <password>y</password>
    <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
    
        <!-- HERE -->
    
        <!-- Checks the Oracle error codes and messages for fatal errors -->
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
          <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
          <metadata>
             <type-mapping>Oracle9i</type-mapping>
          </metadata>
      </local-tx-datasource>
    </datasources>
    

     

    Related

     

    JBoss JCA Main Page