title: Change Hibernate sequence generation for existing data
body: <p>I recently came across <a href="https://stackoverflow.com/questions/5346147/hibernate-oracle-sequence-produces-large-gap">this behavior of Hibernate</a> when trying to move from identity column to sequence based id generation for our business entities. The problem is that we have been using <code>hibernate_sequence</code> generation on Oracle since the first deployment of our application.</p>
  
  <p>So the question is: is it safe to set the following Hibernate's parameter to <code>true</code> on an existing production database without messing up the already generated ids?</p>
  
  <pre><code>hibernate.id.new_generator_mappings=true
  </code></pre>
  
  <p>EDIT: 
  The <a href="http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e855" rel="nofollow noreferrer">Hibernate documentation</a> describes that the change is not backwards compatible with existing databases.</p>
  
  <p>We are using <code>HIBERNATE_SEQUENCE.NEXTVAL</code> in database migrations and this is clearly not at all safe to do, since the <code>NEXTVAL</code> might conflict with a pre-existing id.</p>
  
  <p>If I am not terribly wrong, backwards compatibility could be gained by setting the <code>HIBERNATE_SEQUENCE</code>'s current value to the maximum id in the database. Am I correct? Is there any way to find this out?</p>