title: MyBatis-Spring setup not using transactions
body: <p>I have a web application set up with MyBatis and Spring, but it doesn't seem to be using any transactions. Here's the configuration:</p>
  
  <p>applicationContext.xml:</p>
  
  <pre><code>&lt;tx:annotation-driven /&gt;
  
  &lt;!-- &lt;tx:jta-transaction-manager /&gt; --&gt; &lt;!-- using WebSphere 7 --&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiName" value="jdbc/my_datasource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
      &lt;property name="configLocation" value="WEB-INF/mybatis-config.xml" /&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="testDAO" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt;
      &lt;property name="mapperInterface" value="com.lmig.TestDAO" /&gt;
      &lt;property name="sqlSessionFactory" ref="sqlSessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Sample bean method with transaction definition:</p>
  
  <pre><code>@Transactional(propagation = Propagation.REQUIRED)
  public void testDelete() {
      testDAO.firstDelete(); //always successful
      testDAO.secondDelete(); //always throws SQLServerException
  }
  </code></pre>
  
  <p>TestDAO:</p>
  
  <pre><code>public interface TestDAO {
      public void firstDelete();
      public void secondDelete();
  }
  </code></pre>
  
  <p>Server debug log:</p>
  
  <pre><code>[11/17/11 16:42:07:998 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Creating SqlSession with JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@34ba34ba] 
  [11/17/11 16:42:07:999 PST] 0000002b SystemOut     O DEBUG [java.sql.Connection] ooo Connection Opened 
  [11/17/11 16:42:08:001 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@34ba34ba] will be managed by Spring 
  [11/17/11 16:42:08:005 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@74247424] 
  [11/17/11 16:42:08:025 PST] 0000002b SystemOut     O DEBUG [java.sql.PreparedStatement] ==&gt;  Executing: delete from test1  
  [11/17/11 16:42:08:025 PST] 0000002b SystemOut     O DEBUG [java.sql.PreparedStatement] ==&gt; Parameters:  
  [11/17/11 16:42:08:097 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@74247424] 
  [11/17/11 16:42:08:099 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@74247424] 
  [11/17/11 16:42:08:123 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@74247424] 
  [11/17/11 16:42:08:136 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Creating SqlSession with JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@17351735] 
  [11/17/11 16:42:08:137 PST] 0000002b SystemOut     O DEBUG [java.sql.Connection] ooo Connection Opened 
  [11/17/11 16:42:08:138 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@17351735] will be managed by Spring 
  [11/17/11 16:42:08:139 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d871d87] 
  [11/17/11 16:42:08:145 PST] 0000002b SystemOut     O DEBUG [java.sql.PreparedStatement] ==&gt;  Executing: delete from test2  
  [11/17/11 16:42:08:146 PST] 0000002b SystemOut     O DEBUG [java.sql.PreparedStatement] ==&gt; Parameters:
  [11/17/11 16:42:08:490 PST] 0000002b XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
  [11/17/11 16:42:08:554 PST] 0000002b SQLErrorCodes I org.springframework.jdbc.support.SQLErrorCodesFactory &lt;init&gt; SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
  [11/17/11 16:42:08:560 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d871d87] 
  [11/17/11 16:42:08:597 PST] 0000002b SystemOut     O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d871d87]
  ...SQLServerException follows...
  </code></pre>
  
  <p>Since <code>secondDelete()</code> throws an exception, the entire transaction would be expected to roll back. However, this isn't the case, and the <code>firstDelete()</code> is still committed. I've tried all combinations of the transaction manager config (Spring-managed, app server-managed, both) but I keep getting the same results. Any idea what I'm doing wrong?</p>
  
  <p>I'm using Mybatis 3, Spring 3 on WebSphere 7 with SQL Server 2005 as the DB.</p>