You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Andrey (JIRA)" <ib...@incubator.apache.org> on 2006/07/25 17:49:15 UTC

[jira] Commented: (IBATIS-320) When every method call openSession() return same object .

    [ http://issues.apache.org/jira/browse/IBATIS-320?page=comments#action_12423374 ] 
            
Andrey commented on IBATIS-320:
-------------------------------

I got the same problem, I need separate transactions, but all design in Dao and SqlMap
are the same - all transactions stored in ThreadLocal


Look at  com.ibatis.sqlmap.engine.impl.SqlMapClientImpl (unnecessary code skipped)

public class SqlMapClientImpl implements ExtendedSqlMapClient {

protected ThreadLocal localSqlMapSession = new ThreadLocal();

public SqlMapSession openSession() {
    SqlMapSessionImpl sqlMapSession = getLocalSqlMapSession();
    sqlMapSession.open();
    return sqlMapSession;
}

protected SqlMapSessionImpl getLocalSqlMapSession() {
    SqlMapSessionImpl sqlMapSession = (SqlMapSessionImpl) localSqlMapSession.get();
    if (sqlMapSession == null || sqlMapSession.isClosed()) {
      sqlMapSession = new SqlMapSessionImpl(this);
      localSqlMapSession.set(sqlMapSession);
    }
    return sqlMapSession;
  }

}

As you can see, session always got from ThreadLocal(). 

You can start separate thread, i.e. "Unit Of Work" and do things in it.
I think that this will be more clean desigin...


> When every method call openSession() return same object .
> ---------------------------------------------------------
>
>                 Key: IBATIS-320
>                 URL: http://issues.apache.org/jira/browse/IBATIS-320
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: SQL Maps
>    Affects Versions: 2.1.7
>         Environment: windows xp, x86, mysql, eclipse, ibatis 2.1.7.597
>            Reporter: Hoyoung Hwang
>
> When every method call openSession() return same object .
> i try below code
> ----------------------------------------------
>   Reader reader = Resources.getResourceAsReader("sql-map-config.xml");
>   SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(reader);
>   SqlMapSession sess1 = client .openSession();
>   SqlMapSession sess2 = client .openSession();
>   if(sess1 == sess2) { // <-- this code return true. 
>          System.out.println("equal");    
>   }
>   sess1.startTransaction();
>   sess2.startTransaction(); // <-- error occure :
>   // error description is  TransactionManager could not start a new transaction.  A transaction is already started. 
> -------------------------------------------------------------
> this bugs is discussed in mailing lists
> (http://www.mail-archive.com/user-java@ibatis.apache.org/msg04956.html)
> want to have multiple independent transactions in the same thread.

-- 
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