top of page
Search
Writer's pictureLeonard Anghel

How To Use JPA GenerationType.AUTO And UUID Identifiers

Updated: May 10, 2020

Motivation:

Commonly, UUID are used in clustered environment, where numerical primary keys are prone to conflicts. But, for avoiding conflicts in clustered environments, most relational databases relies on numerical sequences. In other words, each node from the cluster has its own offset used for generating identifiers. Alternatively, but not better, is to use UUID primary keys. But, UUID comes with performance penalties in clustered indexes because their lack of sequentiality and have a bigger memory footprint too. Nevertheless, if you decide to use UUID and assign them automatically then here it i how.


Description:

This application is an example of using the JPA GenerationType.AUTO for assigning automatically UUID identifiers.


Key points:

  • First, store UUID in a BINARY(16) column to have the smallest memory footprint as possible:

Check as well:


Tam Ta Da Dam! :) The complete code is available on GitHub.


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".



1,203 views0 comments

Recent Posts

See All

How To Bulk Updates

Motivation: This article is useful if you need a fast way to update a significant amount of data in the database. Bulk operations...

Comments


bottom of page