Assuming I have a simple hibernate entity like so
@Entity
public class SomeEntity {
@Id
private long id;
// Other fields...
}
I want to generate sequence for the id column with consideration of any deleted entities. Meaning I don't want the sequence to be incremented for every new entity saved to the database, but to reuse values assigned to entities that were deleted. For example in the db I have these entities saved
|---------------------|
| ID |
|---------------------|
| 1 |
|---------------------|
| 2 |
|---------------------|
So the next entity id should get the value 3. But in case the entity with id '1' was deleted, the next time I save an entity to the database I want its id to be '1'
How can this behaviour can be implemented using Hibernate?