| Some databases use upper-case column names. Thus, the schema migrator should use case-insensitive comparison, in case entity column definitions use lower-case column names. Since this is currently not done, the migrator might try to re-create a foreign key and fail, if comparing the name of the foreign key also fails. org.hibernate.tool.schema.internal.AbstractSchemaMigrator.checkForExistingForeignKey:
Predicate<ColumnReferenceMapping> mappingPredicate = m -> {
String existingReferencingColumn = m.getReferencingColumnMetadata().getColumnIdentifier().getText();
String existingReferencedTable = m.getReferencedColumnMetadata().getContainingTableInformation().getName().getTableName().getCanonicalName();
return referencingColumn.equals( existingReferencingColumn ) && referencedTable.equals( existingReferencedTable );
};
To fix this, existingReferencingColumn could be obtained just like existingReferencedTable:
String existingReferencingColumn = m.getReferencingColumnMetadata().getColumnIdentifier().getCanonicalName();
See test case in HibernateMigrationBug.zip |