I recently came across this behavior of Hibernate when trying to move from identity column to sequence based id generation for our business entities. The problem is that we have been using hibernate_sequence
generation on Oracle since the first deployment of our application.
So the question is: is it safe to set the following Hibernate's parameter to true
on an existing production database without messing up the already generated ids?
hibernate.id.new_generator_mappings=true
EDIT: The Hibernate documentation describes that the change is not backwards compatible with existing databases.
We are using HIBERNATE_SEQUENCE.NEXTVAL
in database migrations and this is clearly not at all safe to do, since the NEXTVAL
might conflict with a pre-existing id.
If I am not terribly wrong, backwards compatibility could be gained by setting the HIBERNATE_SEQUENCE
's current value to the maximum id in the database. Am I correct? Is there any way to find this out?