0

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)
sri
  • 148
  • 1
  • 1
  • 9
  • Check my [post](https://stackoverflow.com/a/50882952/5380322), hope it will be helpful... – Cepr0 Aug 03 '19 at 14:54
  • Thanks Cepr0 , but that example uses PostgreSQL and I'm using oracle. Also, all the examples seem to be using @GeneratedValue which is not my case, I have an assigned primary key not generated one. – sri Aug 05 '19 at 14:17

1 Answers1

0

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

WonChul Heo
  • 242
  • 1
  • 12