28

I have a problem with @SequenceGenerator:

@SequenceGenerator(name="pk_user_id", sequenceName="seq_user_id", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="pk_user_id")

When the application starts up it shows warning:

WARN 7388 --- [ main] org.hibernate.orm.deprecation : HHH90000014: Found use of deprecated [org.hibernate.id.SequenceHiLoGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead. See Hibernate Domain Model Mapping Guide for details

I tried to find out how I can replace a deprecated code with a new one but can't find any solution.

VijayD
  • 826
  • 1
  • 11
  • 33
Finchsize
  • 935
  • 2
  • 17
  • 34

2 Answers2

46

According to the warning message and Hibernate documentation (Hibernate deprecated list) you should use SequenceStyleGenerator. Or better use @GenericGenerator and specify generator strategy.

Here is a typical example of usage:
@GenericGenerator(
        name = "wikiSequenceGenerator",
        strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
        parameters = {
                @Parameter(name = "sequence_name", value = "WIKI_SEQUENCE"),
                @Parameter(name = "initial_value", value = "1000"),
                @Parameter(name = "increment_size", value = "1")
        }
)
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
semenchikus
  • 730
  • 8
  • 17
  • 5
    What if the annotations are from JPA ? – bric3 Feb 13 '17 at 14:53
  • 3
    If using Hibernate 4, one can change a property without changing code `properties.put("hibernate.id.new_generator_mappings", "true");` (see [Vlad Mihalcea blog](https://vladmihalcea.com/2014/07/15/from-jpa-to-hibernates-legacy-and-enhanced-identifier-generators/)). However hibernate 5 is using the enhanced generators by default so no need for that property. – bric3 Feb 15 '17 at 14:40
  • Those new sequence generators are using _optimisers_, and the default is the `pooled` one and if this is problematic, you can still avoid issues by using the previous algorythm if you set hibernate to use the **hi/lo** optimizer, for exemple set `properties.put("hibernate.id.optimizer.pooled.preferred", "hilo");`. The benefit is still that there's no change in the code that is using JPA annotations. – bric3 Feb 15 '17 at 14:41
  • i've received 28 messages like this. after changes still receive 28 messages llike this, so, for some reason, did not work for me :( – Andrii Plotnikov Mar 29 '17 at 09:29
  • 8
    If upgrading to Spring Boot 1.4.x, check [this](http://stackoverflow.com/a/39244191/3109776) – AndreLDM Mar 29 '17 at 20:48
  • 1
    Hi, What is allocationSize here in new wikiSequenceGenerator ? – Abhishek-M Jun 13 '17 at 09:41
  • Should be [50](https://github.com/hibernate/hibernate-orm/blob/0a2a5c622e3eb30724e80bc8661c0ac55ebfb2be/hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_1.xsd) – semenchikus Jun 14 '17 at 11:18
0

In my case I had this property:

spring.jpa.hibernate.use-new-id-generator-mappings=false

A colleague had added it by mistake, and it was not needed. After removing it the warning logs were removed.

Hope this helps someone.

Fahad S. Ali
  • 1,284
  • 1
  • 7
  • 7