JPA: Issue with id generation

105 Views Asked by At

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?

1

There are 1 best solutions below

2
On

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.