diff --git a/hibernate-core/src/main/java/org/hibernate/service/schema/internal/SchemaDropperImpl.java b/hibernate-core/src/main/java/org/hibernate/service/schema/internal/SchemaDropperImpl.java index 78805bd5a0c0..3c4d9a3ce3f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/schema/internal/SchemaDropperImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/schema/internal/SchemaDropperImpl.java @@ -74,23 +74,23 @@ public void doDrop(Database database, boolean dropSchemas, Target... targets) th } for ( Table table : schema.getTables() ) { - if ( ! dialect.supportsUniqueConstraintInCreateAlterTable() ) { - for ( UniqueKey uniqueKey : table.getUniqueKeys() ) { - applySqlStrings( uniqueKey, targets, dialect, exportIdentifiers ); - } - } - - for ( Index index : table.getIndexes() ) { - applySqlStrings( index, targets, dialect, exportIdentifiers ); - } + if ( dialect.dropConstraints() ) { + // we need to drop constraints prior to dropping table - if ( dialect.hasAlterTable() ) { for ( ForeignKey foreignKey : table.getForeignKeys() ) { // only add the foreign key if its target is a physical table if ( Table.class.isInstance( foreignKey.getTargetTable() ) ) { applySqlStrings( foreignKey, targets, dialect, exportIdentifiers ); } } + + for ( UniqueKey uniqueKey : table.getUniqueKeys() ) { + applySqlStrings( uniqueKey, targets, dialect, exportIdentifiers ); + } + + for ( Index index : table.getIndexes() ) { + applySqlStrings( index, targets, dialect, exportIdentifiers ); + } } applySqlStrings( table, targets, dialect, exportIdentifiers );