简体   繁体   中英

JPA: Issue with id generation

I am using OpenJPA as ORM tool.

I am facing an issue while persisting an entity. I have used sequence generator for id generation which works perfectly. But there is a scenario where it causes issues.

Suppose there are already some entities in table. Now I freshly deploy my app and persist a new entity. JPA would generate an id, but there is a possibility that already an entity with same id is there in the table. This causes persistence error. So I want that JPA generates value greater than highest id already in table.

How can this be done?

Before you start using the sequence, change its current value to be higher than the current maximum id. For example, this is the way to do it in Oracle; consult the documentation of your database provider.

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