Skip to content
Preptima
hardConceptCodingScenarioMidSeniorStaff

You pass a thousand new entities to saveAll and the database sees a thousand separate inserts. How do you get them batched?

Spring Data JPA saveAll batching needs a Hibernate batch size, statements for the same table kept adjacent, and an identifier strategy that does not force a round trip per row. IDENTITY generation silently prevents insert batching, because Hibernate has to execute each insert to learn the key.

5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Spring Data JPA saveAll is not a true bulk insert; it loops through entities and delegates to save. To make Hibernate batch the resulting inserts, configure hibernate.jdbc.batch_size, keep same-table statements adjacent with ordered inserts, use a sequence or pooled identifier strategy instead of IDENTITY, and flush/clear in chunks so the persistence context does not grow without bound.

Keep spring data jpa explicit in the answer because that is the concept the interviewer is actually trying to test. A good spring data jpa explanation names the trade-off, the failure mode, and the evidence you would use before choosing.

Was this answer helpful?

Likely follow-ups

  • What does a pooled sequence optimiser do to the sequence of identifiers, and does that matter?
  • When would you bypass JPA entirely for a bulk load, and what do you give up?
  • Why does batching an update to a versioned entity need its own setting?
  • How would you prove in an automated test that a save path batches?

Related questions

Further reading