How to replace deprecated MultipleHiLoPerTableGenerator with TableGenerator in Hibernate
Asked Answered
R

1

19

I use hibernate in an application with spring boot 1.4.0.RELEASE.

The Entity for the index looks something along the lines of:

@Entity(name = "SearchableTariffItem")
@Indexed
public class SearchableTariffItem {
    public static final String ZIFFER_ANALYZER_NAME = "ZIFFER_ANALYZER";

    @GeneratedValue(strategy = GenerationType.TABLE)
    @Id
    private Long id;
    ...
}

I now get the following warning when I save the entity for the first time:

2016-08-26 15:08:32.501 WARN 8476 — [apr-8080-exec-6] org.hibernate.orm.deprecation : HHH90000015: Found use of deprecated [org.hibernate.id.MultipleHiLoPerTableGenerator] table-based id generator; use org.hibernate.id.enhanced.TableGenerator instead. See Hibernate Domain Model Mapping Guide for details.

Unfortunately I don't know where I can configure my application (preferably in a the application.yml) to use the TableGenerator class.

I use the following dependency:

  • Hibernate core 5.0.9.Final
  • Hibernate search ORM 5.5.1.Final
  • Lucene 5.3.1
Rotz answered 30/8, 2016 at 13:4 Comment(0)
P
43

The property that controls this behaviour in Hibernate is hibernate.id.new_generator_mappings, which defaults to true for Hibernate 5 -> which means the new TableGenerator will be used instead of the deprecated MultipleHiLoPerTableGenerator .

Spring Boot however defaults this property to false, which means the old generator will be used, unless you explicitly tell it you want the new one. You need to set the property spring.jpa.hibernate.use-new-id-generator-mappings to true to get the TableGenerator.

See https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#generator-mappings

Pigweed answered 31/8, 2016 at 8:15 Comment(3)
Also "alter table hibernate_sequences rename column sequence_next_hi_value to next_val;" might be needed after the changeRotz
Do you know why Spring Boot sets this to false?Cervantez
Spring Boot sets to false to keep backward compatibility, so you don't need to change your database model as commented by leo.Intersect

© 2022 - 2024 — McMap. All rights reserved.