Hibernate auto increase

I use the "increment" hibernation generator to generate auto increment identifiers. This worked fine until I had to add another application that also uses the increment generator to generate new identifiers. I realized that there is a catch with the increment generator:

"generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster."

Is there any way to handle this using sleep mode? Or will I have to write additional code to lock the table, check db for max Id (and then increase it), and finally release the lock? Using a single sleep configuration is not an option. Also, I cannot add the auto_increment parameter to the db table, because we have more than one key in the table.

Any suggestions are welcome, I assume this is a common problem.

+3
source share
1 answer

There are several other generators that can give you what you need:

  • hilo uses the hi / lo algorithm to efficiently generate identifiers of type long, short or int, taking into account the table and column (by default, hibernate_unique_key and next_hi respectively) as a source of hi values. The hi / lo algorithm generates identifiers that are unique to a specific database only.
  • uuid: 128- UUID , ( IP-). UUID 32 .

hi/lo.

auto_increment db, .

- , ?

, - - id, .

+4

Source: https://habr.com/ru/post/1758220/


All Articles