小编典典

Hibernate5序列发生器未提供正确的值

hibernate

迁移到Hibernate 5.2.7之后,我似乎在id字段中得到了不正确的值。

我的代码:

@Id @SearchableId
@GeneratedValue(strategy=GenerationType.AUTO, generator="hms_seq_gen")
@SequenceGenerator(name="hms_seq_gen", sequenceName="patregn_seq")
protected Integer ID;

Hibernate触发以下查询:

select nextval ('patregn_seq')
得出5367。表中id字段的最后一个值为5358。

我明白了
ERROR: duplicate key value violates unique constraint "patientregistration_pkey" [java] Detail: Key (id)=(5318) already exists.

我相信这个问题类似于这个,但我不得不问,因为给出的解决方案有没有为我工作:

我加了

<property value="true" name="hibernate.id.new_generator_mappings"/>

到我的persistence.xml,但无济于事。任何帮助将不胜感激。


阅读 289

收藏
2020-06-20

共1个答案

小编典典

实际上,当您迁移到新的Hibernate版本5.2.7时,hibernate.id.new_generator_mappings默认值为true

为了向后兼容,您应该将此标志更改为false

有关更多信息,请在用户指南中搜索new_generator_mappings:-http :
//docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html

2020-06-20