title: How to suppress auto statement flushing in MyBatis
body: <h2>Background</h2>
  <p>I want to implement the following procedure with Spring and MyBatis:</p>
  <ol>
  <li>Read a line from a CSV file</li>
  <li>Query a table (table <code>ACCOUNT</code>) with values read from the CSV file.</li>
  <li>Merge the values from the CSV file and table <code>ACCOUNT</code> into a record</li>
  <li>Insert the merged record into another table (<code>REGISTRATION</code>)</li>
  </ol>
  <p>I want to use the batch executor (<code>&lt;setting name=&quot;defaultExecutorType&quot; value=&quot;BATCH&quot;/&gt;</code>) because this procedure inserts large number of records.</p>
  <h2>Problem</h2>
  <p>I have implemented the procedure like this:</p>
  <pre class="lang-java prettyprint-override"><code>AccountDao accountDao = applicationContext.getBean(&quot;accountDao&quot;, AccountDao.class);
  RegistrationDao registrationDao = applicationContext.getBean(&quot;registrationDao&quot;, RegistrationDao.class);
  
  List&lt;Registration&gt; list = null;
  try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), &quot;UTF-8&quot;))) {
  
      CsvToBeanBuilder&lt;Registration&gt; builder = new CsvToBeanBuilder&lt;Registration&gt;(reader);
      builder.withType(Registration.class);
  
      list = builder.build().parse();
      for (Registration reg : list) {
          Account account = accountDao.findAccount(reg.getAccountId());
          reg.setName(account.getName());
              ...
          registrationDao.insertRegistration(reg);
      }
  }
  </code></pre>
  <p>I have expected the <code>INSERT</code> SQL to be queued with JDBC <code>Statement#addBatch()</code>, and executed in a batch at the end of the transaction.</p>
  <p>But in actually, MyBatis automatically flush every statement with <code>BatchExecutor#doFlushStatements()</code> when I query <code>ACCOUNT</code> table with <code>AccountDao#findAccount()</code>, so all <code>INSERT</code> SQL are executed separately.</p>
  <p>In this situation, <code>ACCOUNT</code> has no relation to <code>REGISTRATION</code>, so you can safely queue the update statements and execute them in a batch.</p>
  <h2>Question</h2>
  <p>Is there any way to suppress automated flushing of queued statements when the developer knows the queried tables have no relation to the updated tables?</p>