Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

sequence - hibernate 5 sequencegenerator not giving the right value

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...