Skip to content

Latest commit

 

History

History

HibernateSpringBootBulkUpdates

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

How To Bulk Updates

Description: Bulk operations (updates and deletes) are faster than batching, can benefit from indexing, but they have three main shortcomings:

  • bulk updates/deletes may leave the Persistence Context in an outdated state (it's up to you to prevent this issue by flushing the Persistence Context before update/delete and close/clear it after the update/delete to avoid issues created by potentially unflushed or outdated entities)
  • bulk updates/deletes don't benefit of automatic optimistic locking mechanisms (e.g., @Version is ignored), therefore the lost updates are not prevented (it is advisable to signal these updates by explicitly incrementing version (if any is present)).
  • bulk deletes cannot take advantage of cascading removals (CascadeType.REMOVE) and orphanRemoval

This application provides examples of bulk updates for Author and Book entities (between Author and Book there is a bidirectional lazy @OneToMany association). Both, Author and Book, has a version field.

Key points:

  • this application provide an example of bulk updates that don't involve managed entities (data is not loaded in the Persistence Context)
  • this application provide an example of bulk updates that involve managed entities (data is loaded in the Persistence Context before update it via bulk operations)

If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.