Hibernate hi/lo Algorithm And External Systems Issue
Description: This is a Spring Boot sample that exemplifies how the hi/lo algorithm may cause issues when the database is used by external systems as well. Such systems can safely generate non-duplicated identifiers (e.g., for inserting new records) only if they know about the hi/lo presence and its internal work. So, better rely on pooled or pooled-lo algorithm which doesn't cause such issues.
Key points:
- use the
SEQUENCEgenerator type (e.g., in PostgreSQL) - configure the
hi/loalgorithm as inAuthor.javaentity - insert a few records via
hi/lo - insert a few records natively (this acts as an external system that relies on
NEXTVAL('hilo_sequence')and is not aware ofhi/lopresence and/or behavior)
Output sample: Running this application should result in the following error:
ERROR: duplicate key value violates unique constraint "author_pkey"
Detail: Key (id)=(2) already exists.

