如何在 Hibernate 中用 TableGenerator 替换已弃用的 MultipleHiLoPerTableGenerator
How to replace deprecated MultipleHiLoPerTableGenerator with TableGenerator in Hibernate
我在 spring 引导 1.4.0.RELEASE 的应用程序中使用休眠。
索引的实体类似于:
@Entity(name = "SearchableTariffItem")
@Indexed
public class SearchableTariffItem {
public static final String ZIFFER_ANALYZER_NAME = "ZIFFER_ANALYZER";
@GeneratedValue(strategy = GenerationType.TABLE)
@Id
private Long id;
...
}
我现在第一次保存实体时收到以下警告:
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.
不幸的是,我不知道在哪里可以配置我的应用程序(最好在 application.yml 中)以使用 TableGenerator
class.
我使用以下依赖项:
- 休眠核心 5.0.9.Final
- Hibernate 搜索 ORM 5.5。1.Final
- Lucene 5.3.1
在 Hibernate 中控制此行为的 属性 是 hibernate.id.new_generator_mappings
,对于 Hibernate 5,它默认为 true -> 这意味着将使用新的 TableGenerator
而不是弃用的 MultipleHiLoPerTableGenerator
.
Spring 但是启动默认这个 属性 为 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
我在 spring 引导 1.4.0.RELEASE 的应用程序中使用休眠。
索引的实体类似于:
@Entity(name = "SearchableTariffItem")
@Indexed
public class SearchableTariffItem {
public static final String ZIFFER_ANALYZER_NAME = "ZIFFER_ANALYZER";
@GeneratedValue(strategy = GenerationType.TABLE)
@Id
private Long id;
...
}
我现在第一次保存实体时收到以下警告:
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.
不幸的是,我不知道在哪里可以配置我的应用程序(最好在 application.yml 中)以使用 TableGenerator
class.
我使用以下依赖项:
- 休眠核心 5.0.9.Final
- Hibernate 搜索 ORM 5.5。1.Final
- Lucene 5.3.1
在 Hibernate 中控制此行为的 属性 是 hibernate.id.new_generator_mappings
,对于 Hibernate 5,它默认为 true -> 这意味着将使用新的 TableGenerator
而不是弃用的 MultipleHiLoPerTableGenerator
.
Spring 但是启动默认这个 属性 为 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