From 83a477a0d1e09e663a69a5e5a4c14c2a52f43d5d Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 16 Oct 2015 15:08:57 +0100 Subject: [PATCH] HHH-10180 - Fix hbm2ddl tools cannot generate create/update script not modifying the database --- .../schema/internal/SchemaMigratorImpl.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaMigratorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaMigratorImpl.java index 745d18d511..6388ffd977 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaMigratorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaMigratorImpl.java @@ -177,11 +177,7 @@ public class SchemaMigratorImpl implements SchemaMigrator { } final TableInformation tableInformation = existingDatabase.getTableInformation( table.getQualifiedTableName() ); - if ( tableInformation == null ) { - // big problem... - throw new SchemaManagementException( "BIG PROBLEM" ); - } - if ( !tableInformation.isPhysicalTable() ) { + if ( tableInformation != null && !tableInformation.isPhysicalTable() ) { continue; } @@ -267,9 +263,11 @@ public class SchemaMigratorImpl implements SchemaMigrator { continue; } - final IndexInformation existingIndex = findMatchingIndex( index, tableInformation ); - if ( existingIndex != null ) { - continue; + if ( tableInformation != null ) { + final IndexInformation existingIndex = findMatchingIndex( index, tableInformation ); + if ( existingIndex != null ) { + continue; + } } applySqlStrings( @@ -364,19 +362,22 @@ public class SchemaMigratorImpl implements SchemaMigrator { continue; } - final ForeignKeyInformation existingForeignKey = findMatchingForeignKey( foreignKey, tableInformation ); + if ( tableInformation != null ) { + final ForeignKeyInformation existingForeignKey = findMatchingForeignKey( foreignKey, tableInformation ); + if ( existingForeignKey != null ) { + continue; + } + } // todo : shouldn't we just drop+recreate if FK exists? // this follows the existing code from legacy SchemaUpdate which just skipped - if ( existingForeignKey == null ) { - // in old SchemaUpdate code, this was the trigger to "create" - applySqlStrings( - exporter.getSqlCreateStrings( foreignKey, metadata ), - targets, - false - ); - } + // in old SchemaUpdate code, this was the trigger to "create" + applySqlStrings( + exporter.getSqlCreateStrings( foreignKey, metadata ), + targets, + false + ); } }