title: Spring Boot - JPA Repository - Batch Insert not working (Solved)
body: <p>I'm trying to achieve Batch Insert using JpaRepository, but it seems that it doesn't work even though I'm using the recommended properties. This is my code:</p>
  <p>Entity - <code>Book.java</code>:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity(name = &quot;books&quot;)
  @Table(name = &quot;books&quot;)
  public class Book {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      private Long id;
  
      private String title;
  
      private String author;
  
      private String edition;
  
      private String status;
  
      @Column(unique = true)
      private String isbn;
  
      @JsonIgnore
      @OneToMany(cascade = CascadeType.ALL,mappedBy = &quot;book&quot;, fetch = FetchType.LAZY)
      private List&lt;Image&gt; images = new ArrayList&lt;&gt;();
  
  // Getters and Setters omitted
  
  }
  </code></pre>
  <p>Service - <code>BookServiceImpl</code></p>
  <pre class="lang-java prettyprint-override"><code>
  @Service
  public class BookServiceImpl implements BookService {
  
      @Autowired
      private BookRepository bookRepository;
  
      @Override
      public List&lt;Book&gt; storeBooks(List&lt;Book&gt; books) {
  
          return bookRepository.saveAll(books);
      }
  }
  
  </code></pre>
  <p>Properties - <code>application.properties</code>:</p>
  <pre><code>spring.datasource.driver-class-name=org.postgresql.Driver
  spring.datasource.url=jdbc:postgresql://localhost/bookdb?reWriteBatchedInserts=true
  spring.datasource.username=**
  spring.datasource.password=**
  
  spring.jpa.hibernate.ddl-auto=create
  spring.jpa.show-sql=true
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
  spring.jpa.properties.hibernate.jdbc.batch_size=100
  spring.jpa.properties.hibernate.order_inserts=true
  spring.jpa.properties.hibernate.order_updates=true
  spring.jpa.properties.hibernate.generate_statistics=true
  </code></pre>
  <p>SQL Log after inserting:</p>
  <pre><code>Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: select nextval ('hibernate_sequence')
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  Hibernate: insert into books (author, edition, isbn, status, title, id) values (?, ?, ?, ?, ?, ?)
  2021-03-07 09:57:50.163  INFO 7800 --- [nio-8080-exec-1] i.StatisticalLoggingSessionEventListener : Session Metrics {
      2883700 nanoseconds spent acquiring 1 JDBC connections;
      0 nanoseconds spent releasing 0 JDBC connections;
      9612998 nanoseconds spent preparing 10 JDBC statements;
      23803401 nanoseconds spent executing 9 JDBC statements;
      23764601 nanoseconds spent executing 1 JDBC batches;
      0 nanoseconds spent performing 0 L2C puts;
      0 nanoseconds spent performing 0 L2C hits;
      0 nanoseconds spent performing 0 L2C misses;
      275826200 nanoseconds spent executing 1 flushes (flushing a total of 9 entities and 9 collections);
      0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
  </code></pre>
  <p>I don't know if the problem is with the logs or something, but I implemented everything as recommended...</p>