5

After upgrading to Hibernate 5 I am getting the error Found use of deprecated [org.hibernate.id.SequenceGenerator]. I found this answer which has a code snippet mentioning how to solve the problem.

  • I would like to know how that solution works. Does that code snippet do the same thing as the @SequenceGenerator annotation? If so why was the SequenceGenerator deprecated?

  • My annotations are from javax.persistence package. I would prefer to not add hibernate specific stuff in my code. In the answer I have linked there is strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", which is hibernate dependent(at least on the runtime). Is there a way to achieve this?

  • When I set hibernate.id.new_generator_mappings:true I get unique constraint violation errors

Community
  • 1
  • 1
Can't Tell
  • 12,714
  • 9
  • 63
  • 91

1 Answers1

6

To answer my own question,

The above deprecation warning comes because Spring Boot 1.5 sets jpa.properties.hibernate.id.new_generator_mappings: false. If it was set to true, Hibernate will internally use the SequenceStyleGenerator and the warning will not come.

But there would be a difference in the logic that is executed to get the next value of the sequence.

  • With the above setting set to false, org.hibernate.id.SequenceGenerator would have been used, and this does not seem to use the allocationSize parameter of @SequenceGenerator. It will always call the database to get the next value of the sequence. There is another SequenceHiLoGenerator and quoting from its javadoc, An IdentifierGenerator that combines a hi/lo algorithm with an underlying oracle-style sequence that generates hi values. So this can be used together with INCREMENT BY when creating the Orcale Sequence and that generator would not call the database for each insert.

  • With the above setting set to true, Hibernate will by default use a PooledOptimizer which does use allocationSize parameter. Due to this difference in how the ids are generated, I got the unique constraint violation error.

Can't Tell
  • 12,714
  • 9
  • 63
  • 91