title: Spring Transaction Manager: Rollback doesnt work
body: <p>I wish to execute few insert queries within a transaction block where if there is any error all the inserts will be rolled back.</p>
  
  <p>I am using <code>MySQL</code> database and <strong>Spring TransactionManager</strong> for this.
  Also the table type is <code>InnoDB</code></p>
  
  <p>I have done my configuration by following the steps mentioned <a href="http://www.tutorialspoint.com/spring/programmatic_management.htm" rel="nofollow">here</a>.</p>
  
  <p>Following is my code (for now only one query)</p>
  
  <pre><code>TransactionDefinition def = new DefaultTransactionDefinition();
  TransactionStatus status = null;
  
  status = transactionManager.getTransaction(def);
  jdbcTemplate.execute(sqlInsertQuery);
  transactionManager.rollback(status);
  </code></pre>
  
  <p><strong>Spring config xml:</strong></p>
  
  <pre><code>&lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
      &lt;property name="dataSource"&gt;
          &lt;ref bean="dataSource" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Datasource config:</strong></p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
      &lt;property name="url" value="${jdbc.url}" /&gt;
      &lt;property name="username" value="${jdbc.username}" /&gt;
      &lt;property name="password" value="${jdbc.password}" /&gt;
      &lt;property name="initialSize" value="${jdbc.initialSize}" /&gt;
      &lt;property name="maxActive" value="${jdbc.maxActive}" /&gt;
      &lt;property name="minIdle" value="${jdbc.minIdle}" /&gt;
      &lt;property name="maxIdle" value="${jdbc.maxIdle}" /&gt;
      &lt;property name="testOnBorrow" value="${jdbc.testOnBorrow}" /&gt;
      &lt;property name="testWhileIdle" value="${jdbc.testWhileIdle}" /&gt;
      &lt;property name="testOnReturn" value="${jdbc.testOnReturn}" /&gt;
      &lt;property name="validationQuery" value="${jdbc.validationQuery}" /&gt;
      &lt;property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" /&gt;
      &lt;!--&lt;property name="removeAbandoned" value="true"/&gt; &lt;property name="removeAbandonedTimeout" 
          value="10"/&gt; &lt;property name="logAbandoned" value="false"/&gt; --&gt;
      &lt;property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>This code works perfectly fine and the record gets inserted.
  But the rollback doesnt work! It executes the rollback statement without any error but to no effect.</p>
  
  <p>Can anyone guide me where am I going wrong?</p>