Skip to content

Files

Latest commit

 

History

History

HibernateSpringBootNaturalIdCache

How To Use Hibernate @NaturalIdCache For Skipping The Entity Identifier Retrieval

Description: This is a SpringBoot - MySQL application that maps a natural business key using Hibernate @NaturalId. This implementation allows us to use @NaturalId as it was provided by Spring. Moreover, this application uses Second Level Cache (EhCache) and @NaturalIdCache for skipping the entity identifier retrieval from the database.

Key points:

  • enable Second Level Cache (EhCache)
  • annotate entity with @NaturalIdCache for caching natural ids
  • optionally, annotate entity with @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "Book") for caching entites as well

Output sample (for MySQL with IDENTITY generator, @NaturalIdCache and @Cache):


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.