Batch Inserts & Updates — Concept Check
Questions on Batch Inserts & Updates. Enable hibernate.jdbc.batch_size and use SEQUENCE ID generation (not IDENTITY) to allow Hibernate to batch INSERT/UPDATE statements, drastically reducing round-trips.
Questions in this quiz
8 questions on Batch Inserts & Updates — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have enabled `hibernate.jdbc.batch_size` and are using `IDENTITY` for ID generation. What is the effect on batching?
- ABatching works as expected, grouping statements into single round-trips.
- BBatching is disabled because `IDENTITY` requires immediate ID retrieval.
- CBatching is enabled but less efficient due to ID retrieval delays.
- DBatching is partially enabled, but only for `UPDATE` statements.
2.A developer notices that enabling `hibernate.order_inserts` and `hibernate.order_updates` improves performance. Why does this happen?
- AIt reduces the total number of SQL statements executed.
- BIt improves cache efficiency by grouping similar operations.
- CIt automatically increases the batch size beyond the configured limit.
- DIt allows Hibernate to use `IDENTITY` generation more effectively.
3.You configured `hibernate.jdbc.batch_size=50` but observe 1000 SQL statements for 1000 entities. What might be wrong?
- AYou are using `IDENTITY` for ID generation, which disables batching.
- BThe batch size is too small to have any effect.
- CThe database does not support batching, causing the issue.
- DBatching is only effective for UPDATE statements, not INSERTs.
4.What is the role of `entityManager.flush()` in a batch insert loop?
- AIt clears the persistence context, freeing up memory.
- BIt sends the current batch to the database, reducing memory usage.
- CIt increases the batch size dynamically based on memory usage.
- DIt detaches all entities from the session to prevent memory leaks.
5.A developer uses `saveAll()` in Spring Data with a large dataset but experiences high memory usage. What should they do?
- AManually flush and clear the persistence context periodically.
- BEnable `hibernate.order_inserts` to automatically manage memory.
- CIncrease the batch size to handle more entities at once.
- DSwitch to using `IDENTITY` for ID generation to improve efficiency.
6.Which ID generation strategy must be used to enable batching in Hibernate?
- AIDENTITY
- BAUTO
- CUUID
- DSEQUENCE
7.A developer sees the log message "Executing batch size: 1" repeatedly. What is a likely cause?
- ABatching is only configured for UPDATEs, not INSERTs.
- BThe batch size is set too low, causing inefficient batching.
- CThe database does not support batching, leading to single statement execution.
- DThe application is using `IDENTITY` for ID generation, disabling batching.
8.Enabling `hibernate.generate_statistics` helps verify batching. What indicates successful batching?
- AThe batch size dynamically increases based on the dataset size.
- BThe `getPrepareStatementCount()` is much lower than the entity count.
- CThe log shows repeated "Executing batch size: 1" messages.
- DThe application experiences increased memory usage during batch operations.