如何在Hibernate中用TableGenerator替换弃用的MultipleHiLoPerTableGenerator [英] How to replace deprecated MultipleHiLoPerTableGenerator with TableGenerator in Hibernate
问题描述
我在spring boot 1.4.0.RELEASE的应用程序中使用hibernate。
该索引的实体看起来如下所示:
@Entity(name =SearchableTariffItem)
@Indexed
public class SearchableTariffItem {
public static final String ZIFFER_ANALYZER_NAME =ZIFFER_ANALYZER;
@GeneratedValue(strategy = GenerationType.TABLE)
@Id
私人长ID;
...
}
我现在在保存时发出以下警告该实体首次:
2016-08-26 15:08:32.501警告8476 - [apr-8080-exec -6] org.hibernate.orm.deprecation:HHH90000015:找到不推荐使用的[org.hibernate.id.MultipleHiLoPerTableGenerator]基于表的id生成器;改为使用org.hibernate.id.enhanced.TableGenerator。有关详细信息,请参见Hibernate Domain Model Mapping Guide。
不幸的是,我不知道我可以在哪里配置我的应用程序(最好是在application.yml中)使用 TableGenerator
类。
我使用以下依赖项:
TableGenerator
,而不是已弃用的 MultipleHiLoPerTableGenerator
。 Spring Boot默认将此属性设置为false,这意味着将使用旧生成器,除非您明确告诉它你想要新的。
您需要将属性 spring.jpa.hibernate.use-new-id-generator-mappings
设置为 true
来获取TableGenerator。
请参阅 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#generator-mappings
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
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
这篇关于如何在Hibernate中用TableGenerator替换弃用的MultipleHiLoPerTableGenerator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!