You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Jeff Butler (JIRA)" <ib...@incubator.apache.org> on 2006/06/08 19:19:30 UTC

[jira] Commented: (IBATIS-298) implicit commit does not work if there's an explicit commit right before

    [ http://issues.apache.org/jira/browse/IBATIS-298?page=comments#action_12415377 ] 

Jeff Butler commented on IBATIS-298:
------------------------------------

I'm not sure I agree that this is a bug.  If you wrote code like this...

try {
  DaoManager.startTransaction() 
  //1. db insert 1: 
  do db insert 1 
  DaoManager.commitTransaction() 
} finally {
  DaoManager.endTransaction();
}

//an implicit transaction 
do db insert 2 without starting a transaction explicitly. 

...then everything would work like you want it to.  This is the way that we expect and encourage you to do transactions if you are going to do explicit transactions.

Let us know if you still have the problem after adding the finally block as above.


> 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