How to replace deprecated MultipleHiLoPerTableGenerator with TableGenerator in Hibernate

leo picture leo · Aug 30, 2016 · Viewed 7.5k times · Source

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

Answer

Andrei Socaciu picture Andrei Socaciu · Aug 31, 2016

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