Hibernate: duplicate key value violates unique constraint

╄→гoц情女王★ 提交于 2019-12-01 04:06:07

When you create a bigserial column in Postgresql, you are actually creating a sequence. When you manually inserted an ID value of '1', Postgresql did not update the sequence to take this into account. Hibernate lets Postgresql use the sequence to generate the ID, but the first value produced is '1', which clashes. The second value is fine.

If you created the problem by going behind Hibernate and using SQL directly, you should fix it the same way: use ALTER SEQUENCE to set the next value:

alter sequence basedesign_id_seq restart with 2;

With pgAdmin4 I you can change the incrementor to start with 2 (or more) as followings

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