implicit commit does not work if there's an explicit commit right before ------------------------------------------------------------------------
Key: IBATIS-298 URL: http://issues.apache.org/jira/browse/IBATIS-298 Project: iBatis for Java Type: Bug Components: DAO Versions: 2.1.7 Reporter: Bill Liu We've used Ibatis for over 2 years and this's the bug we just found. Consider this scenario: DaoManager.startTransaction() //1. db insert 1: do db insert 1 DaoManager.commitTransaction() //an implicit transaction do db insert 2 without starting a transaction explicitly. What we expected was that the 2 transactions should be committed. However, only the first one was but not the second one. We looked at the source code and found out why: in StandardDaoManager public void endTransaction() { finally { transactionMode.set(null); ... } public void commitTransaction() { List ctxList = getContextInTransactionList(); Iterator i = ctxList.iterator(); while (i.hasNext()) { DaoContext context = (DaoContext) i.next(); context.commitTransaction(); } } Notice in the commitTransaction(), the transactionMode is not set to be null. Now in the second implicit transaction, in com.ibatis.dao.engine.impl.DaoProxy class, invoke(Object proxy, Method method, Object[] args) method, 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(); ... Now daoManager.isExplicitTransaction() returns true! The result: the transaction is started for the second query but never committed! -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira