How to replace deprecated MultipleHiLoPerTableGenerator with TableGenerator in Hibernate

孤人 提交于 2019-12-09 14:14:35

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/39228304/how-to-replace-deprecated-multiplehilopertablegenerator-with-tablegenerator-in-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!