I’m trying to write a SQL script to migrate data from some old table to a new one.
The new table primary key (id) is managed by hibernate, so as the old table’s primary key.
I don’t know how to assign ids for the new table using plain SQL so what i’m doing is to take the ids from the old table.
The migration script works as expected.
In some point, my application tries to insert data to the new table using Hibernate, and I get primary key constraint violation exception. I suspect this is because hibernate assigning keys that collides with the keys I gave when migrating old data.
BTW – hibernate is configured to assign unique primary keys per-table.
What am I doing wrong?
How should I resolve this?
Thanks
If you use database with auto increment for primary (for example mysql, MSSQL)key column you have to set autoincrement value as max from existing ids (after migration).
If you use sequence to generate ids (for example oracle, postgree) you have to change current sequence value to max from existing ids (after migration).