什么';ibatis中SqlMapClient和SqlMapSeision之间有什么不同?

什么';ibatis中SqlMapClient和SqlMapSeision之间有什么不同?,ibatis,spring-orm,Ibatis,Spring Orm,当我阅读ibatis-sqlmap-2.3.4时,我发现它们都实现了SqlMapExecutor SqlMapClientImpl使用localSqlMapSession进行插入,这提供了线程安全性 但在spring2.5.6中,SqlMapClientTemplate的execute方法使用SqlMapClientImpl,如下所示: SqlMapSession session = this.sqlMapClient.openSession(); ... return action

当我阅读ibatis-sqlmap-2.3.4时,我发现它们都实现了SqlMapExecutor

SqlMapClientImpl使用localSqlMapSession进行插入,这提供了线程安全性

但在spring2.5.6中,SqlMapClientTemplate的execute方法使用SqlMapClientImpl,如下所示:

  SqlMapSession session = this.sqlMapClient.openSession();
  ...
  return action.doInSqlMapClient(session);
 return action.doInSqlMapClient(this.sqlMapClient);
openSession方法每次返回一个新的SqlMapSessionImpl

我的问题是:

为什么SqlMapClientTemplate使用SqlMapSeision而不是sqlMapClient

为什么sqlMapClient的localSqlMapSession在SqlMapClientTemplate中未使用?这样使用:

  SqlMapSession session = this.sqlMapClient.openSession();
  ...
  return action.doInSqlMapClient(session);
 return action.doInSqlMapClient(this.sqlMapClient);

SqlMapClient和SQLMapSeision之间有什么不同?

对于第一个问题,spring orm在评论中解释:

// We always need to use a SqlMapSession, as we need to pass a Spring-managed
// Connection (potentially transactional) in. This shouldn't be necessary if
// we run against a TransactionAwareDataSourceProxy underneath, but unfortunately
// we still need it to make iBATIS batch execution work properly: If iBATIS
// doesn't recognize an existing transaction, it automatically executes the
// batch for every single statement...
ibatis的SqlMapClient和SqlMapSession之间差异的答案可以在界面SqlMapClient的注释中找到:

/**
* Returns a single threaded SqlMapSession implementation for use by
* one user.  Remember though, that SqlMapClient itself is a thread safe SqlMapSession
* implementation, so you can also just work directly with it.  If you do get a session
* explicitly using this method <b>be sure to close it!</b>  You can close a session using
* the sqlMapSession.close() method.
* <p/>
*
* @return An SqlMapSession instance.
*/
public SqlMapSession openSession();
/**
*返回单线程SqlMapSession实现,以供用户使用
*一个用户。但是请记住,SqlMapClient本身是线程安全的SqlMapSession
*实现,所以您也可以直接使用它。如果你得到了一个会话
*明确使用此方法时,请确保将其关闭!您可以使用关闭会话
*sqlMapSession.close()方法。
*

* *@返回一个SqlMapSession实例。 */ 公共SqlMapSession openSession();


对于第一个问题,请在评论中解释:

// We always need to use a SqlMapSession, as we need to pass a Spring-managed
// Connection (potentially transactional) in. This shouldn't be necessary if
// we run against a TransactionAwareDataSourceProxy underneath, but unfortunately
// we still need it to make iBATIS batch execution work properly: If iBATIS
// doesn't recognize an existing transaction, it automatically executes the
// batch for every single statement...
ibatis的SqlMapClient和SqlMapSession之间差异的答案可以在界面SqlMapClient的注释中找到:

/**
* Returns a single threaded SqlMapSession implementation for use by
* one user.  Remember though, that SqlMapClient itself is a thread safe SqlMapSession
* implementation, so you can also just work directly with it.  If you do get a session
* explicitly using this method <b>be sure to close it!</b>  You can close a session using
* the sqlMapSession.close() method.
* <p/>
*
* @return An SqlMapSession instance.
*/
public SqlMapSession openSession();
/**
*返回一个单线程SqlMapSession实现供用户使用
*一个用户。但是请记住,SqlMapClient本身是线程安全的SqlMapSession
*实现,所以您也可以直接使用它。如果你得到了一个会话
*明确使用此方法时,请确保将其关闭!您可以使用关闭会话
*sqlMapSession.close()方法。
*

* *@返回一个SqlMapSession实例。 */ 公共SqlMapSession openSession();