迁移到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.
我相信这个问题类似于this和this,但我不得不问,因为那里给出的解决方案对我不起作用:
我补充道
<property value="true" name="hibernate.id.new_generator_mappings"/>
到我的persistence.xml,但无济于事。任何帮助将不胜感激。
实际上当你迁移到新的Hibernate版本5.2.7时,hibernate.id.new_generator_mappings
默认为true
。
为了向后兼容,您应该将此标志更改为false
。
欲了解更多信息,请搜索qazxsw poi用户指南: - qazxsw poi