You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Espenschied, Jim" <Ji...@ps.net> on 2006/10/03 17:45:28 UTC

TransactionManager could not end this transaction

 

I am trying to use iBatis DAOs 2.2.0 build# 638 with IBM Websphere v6
using data source version 4. I am having problems with transactions in
the DaoProxy invoke method. Here is the iBatis code along with the
exception that I get. The exception is thrown from
context.commitTransaction() in the last else statement in DaoProxy. I
can comment out this line and it will work with no exceptions. I have
also included the configuration for my data source and my code that
calls queryForList. Please note that I am overriding the data source
with setUserConnection(connection) and my class with the method
queryForList extends SqlMapDaoTemplate.  I do not need to have any 2
phase commits. What am I missing? Any help would be greatly appreciated.

 

Thanks,

 

Jim

 

    public List queryForList(String name, Object parameters)

    {

        Connection connection = null;

        List results = null;

        try{

           connection = this.getDataSource().getConnection();

 
this.getSqlMapTransactionManager().setUserConnection(connection);

           results = super.queryForList(name, parameters);

           connection.commit();

         } catch (SQLException e) {

             try {

               if (connection != null) connection.rollback();

             } catch (SQLException ignored) {

               // generally ignored

             }

             //throw e;  // rethrow the exception

         } finally {

           try {

             if (connection != null)

             {

                 connection.close();

             }

           } catch (SQLException ignored) {

             // generally ignored

           }

         }

}

 

<transactionManager type="JDBC">

              <dataSource type="JNDI">

                <property name="DataSource" value="jdbc/DataSource"/>

            </dataSource>

</transactionManager>

 

 

public Object invoke(Object proxy, Method method, Object[] args)

      throws Throwable {

    Object result = null;

    if (PASSTHROUGH_METHODS.contains(method.getName())) {

      try {

        result = method.invoke(daoImpl.getDaoInstance(), args);

      } catch (Throwable t) {

        throw ClassInfo.unwrapThrowable(t);

      }

    } else {

      StandardDaoManager daoManager = daoImpl.getDaoManager();

      DaoContext context = daoImpl.getDaoContext();

 

      if (daoManager.isExplicitTransaction()) {

        // Just start the transaction (explicit)

        try {

          context.startTransaction();

          result = method.invoke(daoImpl.getDaoInstance(), args);

        } catch (Throwable t) {

          throw ClassInfo.unwrapThrowable(t);

        }

      } else {

        // Start, commit and end the transaction (autocommit)

        try {

          context.startTransaction();

          result = method.invoke(daoImpl.getDaoInstance(), args);

          context.commitTransaction();

        } catch (Throwable t) {

          throw ClassInfo.unwrapThrowable(t);

        } finally {

          context.endTransaction();

        }

      }

 

    }

    return result;

  }

 

com.ibatis.dao.client.DaoException: Error ending SQL Map transaction.
Cause: com.ibatis.common.jdbc.exception.NestedSQLException: Error while
ending transaction. Cause:
com.ibatis.sqlmap.engine.transaction.TransactionException:
TransactionManager could not end this transaction. A user provided
connection is currently being used by this session. You must call the
rollback() method of the Connection directly. The calling
.setUserConnection (null) will clear the user provided transaction.
Caused by: com.ibatis.sqlmap.engine.transaction.TransactionException:
TransactionManager could not end this transaction. A user provided
connection is currently being used by this session. You must call the
rollback() method of the Connection directly. The calling
.setUserConnection (null) will clear the user provided transaction.