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.

Environment

Mysql 5.6, Linux

Activity

Show:
M
July 6, 2016, 5:47 PM

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

M
December 21, 2016, 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):

M
December 27, 2016, 11:54 PM

In 5.2.6 the class changed to AbstractSchemaMigrator.java

M
December 28, 2016, 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...

Assignee

Chris Cranford

Reporter

M

Fix versions

Labels

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure