Brandon Goodin wrote:

What is your configuration? Were you handling transactions yourself
already or was IBatis handling them for you?




The config file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
   PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
   "http://www.ibatis.com/dtd/sql-map-config-2.dtd";>

<sqlMapConfig>
 <settings
    maxRequests="512"
    maxSessions="128"
    maxTransactions="32"
    cacheModelsEnabled="true"
    lazyLoadingEnabled="true"
    enhancementEnabled="false"
    useStatementNamespaces="false"
  />

  <transactionManager type="JDBC" commitRequired="true">
    <dataSource type="JNDI">
      <property name="DataSource" value="java:comp/env/jdbc/db"/>
    </dataSource>
  </transactionManager>

  <sqlMap resource="com/xentive/admin/admin.xml"/>
  <sqlMap resource="com/xentive/admin/games.xml"/>
  <sqlMap resource="com/xentive/admin/webshop.xml"/>

</sqlMapConfig>


When required we use startTransaction(), commitTransaction() & endTransaction(), but for simple single statement transactions we skip those. It is in this case that we got the problem.


If you look in the file com/ibatis/sqlmap/engine/impl/SqlMapClientImpl.java you see that only in the method endTransaction() does ibatis call getLocalSqlMapSession().close(). Which means that unless you somehow invoke endTransaction(), the session never gets closed.

// Not OK - leaves the session open:
try
{
 sqlMapClient.update("updateSomething",null);
} catch (SQLException e)
{
}

The above code leaves the session open, and if the thread never again does any ibatis call, for example because the thread got terminated, the session just hangs around forever. Adding a finally clause with sqlMapClient.endTransaction() fixes this, but if that is required it is not documented. From the documentation I get the impression that you are only required to use endTransaction() if you use startTransaction().

// OK - closes the session after use:
try
{
sqlMapClient.update("updateSomething",null);
} catch (SQLException e)
{
} finally
{
try
{
// we never called startTransaction(), but endTransaction() is required anyway to force session.close()
sqlMapClient.endTransaction();
} catch (SQLException e)
{
}
}


Baldur



Reply via email to