简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM