title: Hibernate Batch processing
body: <p>So I am trying to configure Hibernate for batch processing purposes. I have built a sample application and configured according to Hibernates docs.</p>
  
  <p>But after configuring Hibernate to log out the SQL, it looks like it is not performing a batch insert at all but merely individual inserts. Am I reading this log wrong?</p>
  
  <p>So I have the following properties configured in my Spring Boot app.</p>
  
  <pre><code>spring.jpa.properties.hibernate.jdbc.batch_size=10
  spring.jpa.properties.hibernate.show_sql=true
  spring.jpa.properties.hibernate.format_sql=true
  </code></pre>
  
  <p>Here is my very basic Batch Writer..</p>
  
  <p><code>@Transactional
  public class BatchWriter {</p>
  
  <pre><code>private EntityManager entityManager;
  
  private int batchSize;
  
  public BatchWriter(EntityManager entityManager, int batchSize) {
      this.entityManager = entityManager;
      this.batchSize = batchSize;
  }
  
  public void writeBatchOfCustomers(int numOf) {
      for(long i = 0; i &lt;= numOf; i++) {
          Customer customer = new Customer(i);
          entityManager.persist(customer);
  
          if ( i % batchSize == 0 ) { //20, same as the JDBC batch size
              //flush a batch of inserts and release memory:
              entityManager.flush();
              entityManager.clear();
          }
      }
  }
  </code></pre>
  
  <p>}</code></p>
  
  <p>Now I am running this to insert 20 Customers for example and in the hibernate log I am seeing the following 20 times:</p>
  
  <pre><code>Hibernate: 
  insert 
  into
      customer
      (first_name, last_name, id) 
  values
      (?, ?, ?)
  </code></pre>
  
  <p>What am I missing here?</p>
  
  <p>It is currently using Spring Boot auto configuration with H2 database. I will however be looking to use it with Spring Batch and an Oracle db eventually, which will be inserting around 30k objects with about 35 attributes.</p>
  
  <p>Any help appreciated.</p>
  
  <p>Thanks,</p>