title: Spring Boot MySQL not batching inserts
body: <p>I've applied pretty much all solutions posted here on SO regarding this issue but nothing worked.</p>
  
  <p>My <strong>application.properties</strong>:</p>
  
  <pre><code>spring.jpa.hibernate.ddl-auto=create-drop
  spring.datasource.url=jdbc:mysql://localhost:3306/mydb?logger=com.mysql.jdbc.log.Slf4JLogger&amp;rewriteBatchedStatements=true&amp;profileSQL=true&amp;autoReconnect=true&amp;useSSL=false
  spring.datasource.username=user
  spring.datasource.password=secret
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  
  spring.jpa.hibernate.jdbc.batch_size = 100
  spring.jpa.hibernate.order_inserts   = true 
  spring.jpa.hibernate.order_updates   = true
  
  logging.level.root=info
  logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5p) %gray(%c{0}::%M) - %m%n
  </code></pre>
  
  <p>My <strong>EntityRepository</strong>:</p>
  
  <pre><code>@Repository
  public interface EntityRepository extends CrudRepository&lt;Entity, Long&gt; { }
  </code></pre>
  
  <p>My <strong>Entity</strong>:</p>
  
  <pre><code>@Data @Entity
  public class Entity {
  
    @Id
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "increment")
    private Long id;
  
    private Long attr;
  
  }
  </code></pre>
  
  <p>And the simplified code that calls repository:</p>
  
  <pre><code>int batchSize = 100;
  List&lt;Entity&gt; batchEntities = new ArrayList&lt;&gt;();
  for(Entity entity : entities) {
    batchEntities.add(entity);
    if(batchEntities.size() &gt;= batchSize) {
      entityRepository.saveAll(batchEntities);
      batchEntities.clear();
    }
  }
  </code></pre>
  
  <p>What I've done:</p>
  
  <p>As per <a href="https://stackoverflow.com/questions/21530112/no-matter-what-i-cant-batch-mysql-insert-statements-in-hibernate" title="No matter what, I can&#39;t batch MySQL INSERT statements in Hibernate">this SO question</a> I've enabled the <code>profileSQL=true</code> option and the log produces several individual inserts. Also, I've enabled global logging on SQL server and it too produces sequence of individual inserts.</p>
  
  <p>As per <a href="https://stackoverflow.com/questions/47632045/spring-boot-jpa-bulk-insert" title="Spring Boot JPA Bulk insert">this another SO question</a> and <a href="https://stackoverflow.com/questions/50772230/how-to-do-bulk-multi-row-inserts-with-jparepository" title="How to do bulk &#40;multi row&#41; inserts with JpaRepository?">yet another SO question</a> I've made sure that <code>batch_size</code> is set in the <code>application.properties</code> file and although I have no parent-child relationship I've also tried to use the <code>order_inserts</code> and <code>order_updates</code>. Also, I've enabled the <code>rewriteBatchedStatements=true</code> option and use the <code>saveAll(...)</code> method.</p>
  
  <p>I've also tried to ditch the premade <code>CrudRepository</code> and my a custom one, by flushing after every <code>batchSize</code>-th persist. </p>
  
  <p>Nothing above helped.</p>