hibernate 5 sequencegenerator not giving the right value

六月ゝ 毕业季﹏ 提交于 2019-11-26 23:21:42

问题


After migrating to Hibernate 5.2.7, I seem to be getting incorrect values for the id field.

My code:

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

Hibernate fires this query:

select nextval ('patregn_seq')
which gives 5367. The last value in the id field in the table is 5358.

And I get this
ERROR: duplicate key value violates unique constraint "patientregistration_pkey" [java] Detail: Key (id)=(5318) already exists.

I am sure this question is similar to this and this, but I am forced to ask because the solution given there does not work for me:

I added

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

to my persistence.xml, but to no avail. Any help would be greatly appreciated.


回答1:


Actually when you migrate to the new Hibernate version 5.2.7, hibernate.id.new_generator_mappings defaults to true.

For backward compatibility you should change this flag to false.

For more information please search the userguide for new_generator_mappings: - http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html



来源:https://stackoverflow.com/questions/42228150/hibernate-5-sequencegenerator-not-giving-the-right-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!