title: How to avoid commit for mybatis sql session in a multi-thread context
body: <p>I have a restful service which use mybatis for the persistence layer. I use SqlSessionTemplate. Now for test, I start the war in a embedded tomcat in Maven and then share the context with my tests. So they can use the same db connection. I was hoping the tests can be done in transactions. For each test scenario, data get setup at beginning and rollback after the test. Meanwhile, I used SingleConnectionDataSource for datasource, so all the session will share the same db connection.</p>
  
  <p>But I found since the restful service is multi-thread. It turns out every session will in a thread, so the SqlSession need to be closed, so the session forced commit on the connection. Just wondering how can i avoid the commit?</p>
  
  <pre><code>SqlSession sqlSession = getSqlSession(
        SqlSessionTemplate.this.sqlSessionFactory,
        SqlSessionTemplate.this.executorType,
        SqlSessionTemplate.this.exceptionTranslator);
    try {
      Object result = method.invoke(sqlSession, args);
      if (!isSqlSessionTransactional(sqlSession, SqlSessionTemplate.this.sqlSessionFactory)) {
        // force commit even on non-dirty sessions because some databases require
        // a commit/rollback before calling close()
        sqlSession.commit(true);
      }
      return result;
  </code></pre>
  
  <p>Here is the code of SqlSessionInterceptor, you can see it checks isSqlSessionTransactional(), then it force sqlSession to commit. </p>