From 09baefba40e77b2af40314bd1162a06b839a2209 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Thu, 25 Jul 2024 12:29:40 +0200 Subject: [PATCH] HHH-18406 Drop and recreate UserDefinedTypes for schema update as well --- .../tool/schema/internal/AbstractSchemaMigrator.java | 8 ++++++++ .../hibernate/tool/schema/internal/SchemaCreatorImpl.java | 2 +- .../hibernate/tool/schema/internal/SchemaDropperImpl.java | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java index 606ade6d43..3230f861b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java @@ -59,6 +59,8 @@ import static org.hibernate.engine.config.spi.StandardConverters.STRING; import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.tool.schema.UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY; import static org.hibernate.tool.schema.UniqueConstraintSchemaUpdateStrategy.SKIP; +import static org.hibernate.tool.schema.internal.SchemaCreatorImpl.createUserDefinedTypes; +import static org.hibernate.tool.schema.internal.SchemaDropperImpl.dropUserDefinedTypes; /** * Base implementation of {@link SchemaMigrator}. @@ -195,6 +197,9 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { } } + // Drop all UDTs + dropUserDefinedTypes( metadata, options, schemaFilter, dialect, formatter, sqlGenerationContext, targets ); + // Create before-table AuxiliaryDatabaseObjects for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) { if ( auxiliaryDatabaseObject.beforeTablesOnCreation() @@ -209,6 +214,9 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { } } + // Recreate all UDTs + createUserDefinedTypes( metadata, options, schemaFilter, dialect, formatter, sqlGenerationContext, targets ); + boolean tryToCreateCatalogs = false; boolean tryToCreateSchemas = false; if ( options.shouldManageNamespaces() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java index 0c14121122..78ad8d5190 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java @@ -497,7 +497,7 @@ public class SchemaCreatorImpl implements SchemaCreator { } } - private static void createUserDefinedTypes( + static void createUserDefinedTypes( Metadata metadata, ExecutionOptions options, SchemaFilter schemaFilter, diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java index d568bd8d52..2f1455d15d 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java @@ -391,7 +391,7 @@ public class SchemaDropperImpl implements SchemaDropper { } } - private static void dropUserDefinedTypes( + static void dropUserDefinedTypes( Metadata metadata, ExecutionOptions options, SchemaFilter schemaFilter,