Sarah92
Sarah92

Reputation: 671

Hibernate JPA check for a conflict when generating IDs

I am using a postgresql database table which may have inserts with the ID set manually by the user, or need an ID generated using hibernate.

This may lead to the occurrence of generating an ID which has already been inserted into the database manually. Is there any way hibernate can check for collisions between the generated ID and existing IDs?

Upvotes: 1

Views: 677

Answers (1)

Vlad Mihalcea
Vlad Mihalcea

Reputation: 154070

Hibernate cannot check that, because the sequence is allocated by the database. You could either:

  1. assign negative numbers for manually inserted IDs
  2. use UUID instead of sequences

Upvotes: 1

Related Questions