Java – hibernate primary key constraint violation

I'm trying to write an SQL script to migrate data from some old tables to a new table

Sometimes my application tries to insert data into a new table using hibernate, and I get a primary key constraint violation exception I suspect this is because the key distributed by hibernate conflicts with the key I gave when migrating old data BTW - hibernate is configured to assign a unique primary key to each table

What on earth did I do wrong? How can I solve this problem?

thank you

Solution

If you use a database (such as mysql, MSSQL) key column with automatic increment, you must set the automatic increment value of the existing ID to max (after migration) If you use a sequence to generate an ID (for example, Oracle, posttree), you must change the current sequence value from the existing ID to max (after migration)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>