Transaction cleanup problem in WebSphere Application Server 6.1.0.19 (Root cause already identified) ----------------------------------------------------------------------------------------------------
Key: IBATIS-560 URL: https://issues.apache.org/jira/browse/IBATIS-560 Project: iBatis for Java Issue Type: Bug Components: SQL Maps Affects Versions: 2.3.4 Environment: WebSphere Application Server 6.1.0.19, Windows XP, DB2 v9.1 Reporter: LiuYang We are using ibatis 2.3.4 in a struts 2 web app with IBM WebSphere Application Server data source and DB2 v9.1. No spring or other framework involved. The code we used is very simple like the following: SqlMapClient sqlMapper = null; try { Reader reader = Resources.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml"); sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e); } try { sqlMapper.startTransaction(); //some work sqlMapper.commitTransaction(); } catch (SQLException e) { //some error handling }finally{ try { sqlMapper.endTransaction(); } catch (SQLException e1) { e1.printStackTrace(); } } The transaction manager definition is the following: <transactionManager type="JDBC"> <dataSource type="JNDI"> <property name="DataSource" value="jdbc/test" /> <!-- we use DB2 v9.1 type 4 driver to define this data source --> </dataSource> </transactionManager> We found that if our db operation is complex (some update, search, insert), our app works correctly. But if we only do the query, we will meet with the following exception: com.ibm.ws.exception.WsException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction.. at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.<init>(DataStoreAdapterException.java:241) at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.<init>(DataStoreAdapterException.java:190) at com.ibm.ws.rsadapter.AdapterUtil.createDataStoreAdapterException(AdapterUtil.java:353) at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.cleanupTransactions(WSRdbManagedConnectionImpl.java:3702) at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.cleanup(WSRdbManagedConnectionImpl.java:3298) at com.ibm.ejs.j2c.MCWrapper.cleanup(MCWrapper.java:1449) at com.ibm.ejs.j2c.FreePool.returnToFreePool(FreePool.java:485) at com.ibm.ejs.j2c.PoolManager.release(PoolManager.java:1780) at com.ibm.ejs.j2c.MCWrapper.releaseToPoolManager(MCWrapper.java:2281) at com.ibm.ejs.j2c.ConnectionEventListener.connectionClosed(ConnectionEventListener.java:324) at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.processConnectionClosedEvent(WSRdbManagedConnectionImpl.java:1570) at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.closeWrapper(WSJdbcConnection.java:816) at com.ibm.ws.rsadapter.jdbc.WSJccConnection.closeWrapper(WSJccConnection.java:724) at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:181) at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:140) at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:86) at com.ibatis.sqlmap.engine.transaction.TransactionManager.end(TransactionManager.java:93) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.endTransaction(SqlMapExecutorDelegate.java:734) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.endTransaction(SqlMapSessionImpl.java:176) at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.endTransaction(SqlMapClientImpl.java:153) at com.mydomain.data.TestService.test(TestService.java:42) at lius.HelloWorldAction.execute(HelloWorldAction.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:618) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48) After several days debug, I found maybe the root cause is: no connection.commit() before connection.close(); If the transaction only contains select clause, ibatis WON'T call connection.commit() even we called sqlMapper.commitTransaction(). I've debuged using ibatis source code and proved this. It would be great if this could be fixed since our work around now is to use sqlMapper.setUserConnection() which will bypass transaction management of Ibatis. Thanks a lot. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.