1 Reply Latest reply on Mar 19, 2007 2:08 PM by adrian.brock

    Setting isolation level for certain Connection

    kkrivopustov

      Hello,
      I use Hibernate with JBoss EJB3 session beans, and I need to decrease isolation level for some method to eliminate a concurrency issue.

      Is it possible to get the Connection from current Hibernate session, set appropriate isolation level, make call to database through this connection, and close it?

      As I understand, when I close Connection, it is returned into connection pool. When next EJB method gets this connection from the pool, will it be set to my last isolation level or to default (set in *-ds.xml)?
      So is it correct to set isolation level for pooled connection?

        • 1. Re: Setting isolation level for certain Connection

          Use the source Luke :-)

          ManagedConnection.cleanup() is invoked as part of the JCA spec
          contract when a connection is returned to the pool.

          org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection
          
           public void cleanup() throws ResourceException
           {
          <snipped/>
          
           //reset all the properties we know about to defaults.
           synchronized (stateLock)
           {
           jdbcAutoCommit = true;
           jdbcReadOnly = readOnly;
           if (jdbcTransactionIsolation != transactionIsolation)
           {
           try
           {
           con.setTransactionIsolation(jdbcTransactionIsolation);
           jdbcTransactionIsolation = transactionIsolation;
           }
           catch (SQLException e)
           {
           mcf.log.warn("Error resetting transaction isolation ", e);
           }
           }
           }
           }