Batching inserts and updates
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) andorder_inserts/order_updatesto group statements. GenerationType.IDENTITYforces Hibernate to insert each row immediately to get the id, which disables insert batching.- Use a sequence (
GenerationType.SEQUENCEwithallocationSizematching the sequence increment) to batch inserts. - With the PostgreSQL driver,
reWriteBatchedInserts=truemerges inserts further (verify driver option before recording). - Flush and clear the persistence context every batch to keep memory flat.
Draft outline details
Demonstration
spring.jpa.properties.hibernate.jdbc.batch_size: 50
spring.jpa.properties.hibernate.order_updates: trueCheck 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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.