ankit.vishen
ankit.vishen

Reputation: 1170

Does JPA saveall method uses hibernate batch to update/insert

I've 1000 entities to update in MySQL database so If I use myRepository.saveAll(List<Entity>) does it internally use hibernate batch to update the table. I'm using below hibernate property for batch update/insert

spring.jpa.properties.hibernate.jdbc.batch_size=100
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true

I'm wondering if JPA will execute 10 queries to update in batch or will work same as JPA save(Entity) method and execute 1000 queries to update ? Is there any way to trace it ?

Upvotes: 0

Views: 3637

Answers (1)

JB Nizet
JB Nizet

Reputation: 691913

saveAll() is just a loop calling save() on each entity. It can't be anything else, as JPA doesn't have any method to save several entities at once.

Does that mean that hibernate batching isn't used? No, because Hibernate batching precisely consists in grouping insert queries in batches, and execute the batches.

Upvotes: 2

Related Questions