top of page
Search
Writer's pictureLeonard Anghel

Why And How To Avoid The AUTO Generator Type In Hibernate 5/6 And MySQL

Updated: May 10, 2020

Motivation:

From the performance perspective, the TABLE generator has significant issues. It should be avoided.

150+ PERSISTENCE PERFORMANCE ITEMS

THAT WILL ROCK YOUR APPS

Description:

In MySQL & Hibernate 5/6, the GenerationType.AUTO generator type will result in using the TABLE generator. This adds a significant performance penalty. Turning this behavior to IDENTITY generator can be obtained by using GenerationType.IDENTITY or the native generator.


Key points:

  • Avoid GenerationType.AUTO (avoid the following code):

  • Prefer GenerationType.IDENTITY instead of GenerationType.AUTO:

  • Or, prefer the native generator:

Testing time:

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


259 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