Spring Boot – Batch updates inserts records individually instead of in a batch

I’m trying to do a batch insert (spring boot, jpa, hibernate) and when I look at the generated statistics, realized that it is still inserting them one by one instead as a batch . Below is the configuration and using JpaRepository’s saveAll(collection) method. My only hunch is, I’m using an assigned primary key instead of a generated one, not sure if that is the cause.

How do I solve the problem?

properties

spring.jpa.properties.hibernate.jdbc.batch_size=10
spring.jpa.properties.hibernate.order_inserts = true
spring.jpa.properties.hibernate.order_updates = true
spring.jpa.properties.hibernate.batch_versioned_data=true
spring.jpa.properties.hibernate.generate_statistics=true
   @Id
   @Column(name = "SKU")
   private String sku;

Statistics:

43972157 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
128270518 nanoseconds spent preparing 10 JDBC statements;
1320687164 nanoseconds spent executing 8 JDBC statements;
126666002 nanoseconds spent executing 2 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
152061315 nanoseconds spent executing 2 flushes (flushing a total of 16 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

It would be nice to adjust chunk of step and hibernate.jdbc.batch_size of hibernate.