Skip to content

Latest commit

 

History

History

HibernateSpringBootElementCollectionWithOrderColumn

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

How @ElementCollection With @OrderColumn Works

Description: This application reveals the performance penalties of using @ElementCollection. In this case, with @OrderColumn. But, as you can see in this application (in comparison with item 33), by adding @OrderColumn can mitigate some performance penalties when operations takes place near the collection tail (e.g., add/remove at/from the end of the collection). Mainly, all elements situated before the adding/removing entry are left untouched, so the performance penalty can be ignored if we affect rows close to the collection tail.

Key points:

  • an @ElementCollection doesn't have a primary key
  • an @ElementCollection is mapped in a separate table
  • prefer @ElementCollection with @OrderColumn when you have a lot of inserts and deletes near the collection tail
  • the more elements are inserted/removed from the beginning of the collection the greater the performance penalty will be

Output example:


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.