title: How to implement batch operations with MyBatis/Spring?
body: <p>I am wondering how to implement batch operations with my insert statements using MyBatis 3 &amp; Spring 3?</p>
  
  <p>For example, here is what is currently being done:</p>
  
  <p>spring.xml:</p>
  
  <pre><code>&lt;bean id="jndiTemplateDatasource" class="org.springframework.jndi.JndiTemplate"&gt;
      &lt;property name="environment"&gt;
        &lt;props&gt;
          &lt;prop key="java.naming.factory.initial"&gt;${context.factory}&lt;/prop&gt;
        &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
    &lt;property name="jndiTemplate" ref="jndiTemplateDatasource"/&gt;
    &lt;property name="jndiName" value="${connectionpool.jndi}"/&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;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="configLocation" value="classpath:mybatis-config.xml"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt;
    &lt;property name="basePackage" value="com.test" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>MyService.xml:</p>
  
  <pre><code>&lt;insert id="insertMyRecord" parameterType="com.test.MyRecord"  &gt;
     insert into ... // code removed
  &lt;/insert&gt; 
  </code></pre>
  
  <p>MyService.java:</p>
  
  <pre><code>public interface MyService {
  
    public void insertMyRecord (MyRecord);
  }
  </code></pre>
  
  <p>MyController.java:</p>
  
  <pre><code>@Controller
  public class MyController {
  
    @Autowired
    private MyService myService;
  
    @Transactional
    @RequestMapping( .... )
    public void bulkUpload (@RequestBody List&lt;MyRecord&gt; myRecords) {
      for (MyRecord record : myRecords) {
        myService.insertMyRecord(record);
      }
    }
  }
  </code></pre>
  
  <p>Disclaimer: That is just pseudo code for demonstration purposes</p>
  
  <p>So what can I do to turn that into a batch process?</p>
  
  <p>Ideally I want to be able to do it with least "intrusion" into code, i.e. use annotations more preferred, but if not possible what is the next best thing?</p>
  
  <p>Also, this needs to be configured just for this one service, not for everything in the project.</p>