Java 替换 @SequenceGenerator 因为它已被弃用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39861098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replace @SequenceGenerator since its deprecated
提问by Finchsize
I have a problem with @SequenceGenerator
:
我有以下问题@SequenceGenerator
:
@SequenceGenerator(name="pk_user_id", sequenceName="seq_user_id", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="pk_user_id")
When the application starts up it shows warning:
当应用程序启动时,它会显示警告:
WARN 7388 --- [ main] org.hibernate.orm.deprecation : HHH90000014: Found use of deprecated [org.hibernate.id.SequenceHiLoGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead. See Hibernate Domain Model Mapping Guide for details
WARN 7388 --- [main] org.hibernate.orm.deprecation : HHH90000014: 发现使用已弃用的 [org.hibernate.id.SequenceHiLoGenerator] 基于序列的 id 生成器;使用 org.hibernate.id.enhanced.SequenceStyleGenerator 代替。有关详细信息,请参阅 Hibernate 域模型映射指南
I tried to find out how I can replace a deprecated code with a new one but can't find any solution.
我试图找出如何用新代码替换已弃用的代码,但找不到任何解决方案。
采纳答案by semenchikus
According to the warning message and Hibernate documentation (Hibernate deprecated list) you should use SequenceStyleGenerator. Or better use @GenericGeneratorand specify generator strategy.
根据警告消息和 Hibernate 文档(Hibernate 弃用列表),您应该使用SequenceStyleGenerator。或者更好地使用@GenericGenerator并指定生成器策略。
下面是一个典型的用法示例:@GenericGenerator(
name = "wikiSequenceGenerator",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {
@Parameter(name = "sequence_name", value = "WIKI_SEQUENCE"),
@Parameter(name = "initial_value", value = "1000"),
@Parameter(name = "increment_size", value = "1")
}
)
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")