Preventing duplicate ForeignKey generation

Description

When hbm2ddl.auto is set to update all tables and keys are checked to see if changes are needed. The algorith by which the names of the foreign keys are generated changed the last couple of versions. Now the update thinks the foreign keys don't exist and creates them again.

By changing findMatchingForeignKey in SchemaMigratorImpl to check the actual reference and fields that could be a lot smarter. So don't purely match on keyname but instead on the field and the referenced table with the referenced field.

Activity

Show:

Milo van der Zee December 28, 2016 at 11:47 AM

'gradle compile test' done and all tests pass. At least in folder hibernate-core. Did not test it for all but that doesn't seem necessary to me...

Milo van der Zee December 27, 2016 at 11:54 PM

In 5.2.6 the class changed to AbstractSchemaMigrator.java

Milo van der Zee December 21, 2016 at 12:06 PM
Edited

Replace the existing method findMatchingForeignKey() with the following code

Or the Java8 way:

And when the calling function is also changed (it does not use the returned key):

Milo van der Zee July 6, 2016 at 5:47 PM

And also add some debug info to the steps done during updating the schema.

Fixed

Details

Assignee

Reporter

Labels

Original estimate

Time tracking

No time logged4h remaining

Components

Fix versions

Priority

Created July 6, 2016 at 4:24 PM
Updated August 20, 2021 at 9:25 AM
Resolved June 7, 2017 at 5:13 PM