Skip to content
Ameen Abozaid
Planned lessonMID-021-L02

Batching inserts and updates

  • Lesson 2 of 6
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

send many statements to the database in few round trips.

Planned topics

  • Set hibernate.jdbc.batch_size (for example 50) and order_inserts/order_updates to group statements.
  • GenerationType.IDENTITY forces Hibernate to insert each row immediately to get the id, which disables insert batching.
  • Use a sequence (GenerationType.SEQUENCE with allocationSize matching the sequence increment) to batch inserts.
  • With the PostgreSQL driver, reWriteBatchedInserts=true merges inserts further (verify driver option before recording).
  • Flush and clear the persistence context every batch to keep memory flat.
Draft outline details

Demonstration

yaml
spring.jpa.properties.hibernate.jdbc.batch_size: 50
spring.jpa.properties.hibernate.order_updates: true

Check your understanding

Why does IDENTITY stop insert batching?

Show answer

Hibernate must execute each insert at once to learn the generated id.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.