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 dcb2d773e4..77022cf521 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 @@ -524,8 +524,13 @@ public class SchemaCreatorImpl implements SchemaCreator { } String charsetName = (String) options.getConfigurationValues().get( HBM2DDL_CHARSET_NAME ); + boolean hasDefaultImportFileScriptBeenExecuted = false; if ( importScriptSetting != null ) { final ScriptSourceInput importScriptInput = interpretScriptSourceSetting( importScriptSetting, classLoaderService, charsetName ); + final URL defaultImportFileUrl = classLoaderService.locateResource( DEFAULT_IMPORT_FILE ); + if ( defaultImportFileUrl != null && importScriptInput.containsScript( defaultImportFileUrl ) ) { + hasDefaultImportFileScriptBeenExecuted = true; + } final List commands = importScriptInput.extract( reader -> commandExtractor.extractCommands( reader, dialect ) ); @@ -537,7 +542,7 @@ public class SchemaCreatorImpl implements SchemaCreator { final String importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, options.getConfigurationValues(), - DEFAULT_IMPORT_FILE + hasDefaultImportFileScriptBeenExecuted ? "" : DEFAULT_IMPORT_FILE ); for ( String currentFile : importFiles.split( "," ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputAggregate.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputAggregate.java index 7fbba6d21b..a611f5bf37 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputAggregate.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputAggregate.java @@ -7,6 +7,7 @@ package org.hibernate.tool.schema.internal.exec; import java.io.Reader; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -62,6 +63,16 @@ public class ScriptSourceInputAggregate implements ScriptSourceInput { return list; } + @Override + public boolean containsScript(URL url) { + for ( int i = 0; i < inputs.length; i++ ) { + if ( inputs[i].containsScript( url ) ) { + return true; + } + } + return false; + } + @Override public String toString() { return "ScriptSourceInputAggregate(" + Arrays.toString( inputs ) + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java index 4500cc96d2..41de334526 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java @@ -11,6 +11,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.net.URL; import org.hibernate.tool.schema.spi.SchemaManagementException; @@ -86,6 +87,11 @@ public class ScriptSourceInputFromFile extends AbstractScriptSourceInput { } } + @Override + public boolean containsScript(URL url) { + return file.getAbsolutePath().equals( url.getPath() ); + } + @Override public String toString() { return "ScriptSourceInputFromFile(" + file.getAbsolutePath() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromReader.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromReader.java index f5c778ddd9..855964d13e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromReader.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromReader.java @@ -7,6 +7,7 @@ package org.hibernate.tool.schema.internal.exec; import java.io.Reader; +import java.net.URL; /** * ScriptSourceInput implementation for explicitly given Readers. @@ -40,6 +41,11 @@ public class ScriptSourceInputFromReader extends AbstractScriptSourceInput { // nothing to do } + @Override + public boolean containsScript(URL url) { + return false; + } + @Override public String toString() { return "ScriptSourceInputFromReader()"; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java index 15247bfdc6..8229327094 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java @@ -67,6 +67,11 @@ public class ScriptSourceInputFromUrl extends AbstractScriptSourceInput { } } + @Override + public boolean containsScript(URL url) { + return url.equals( url ); + } + @Override public String toString() { return "ScriptSourceInputFromUrl(" + url.toExternalForm() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputNonExistentImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputNonExistentImpl.java index ab23769050..97db78143a 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputNonExistentImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputNonExistentImpl.java @@ -7,6 +7,7 @@ package org.hibernate.tool.schema.internal.exec; import java.io.Reader; +import java.net.URL; import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -39,6 +40,11 @@ public class ScriptSourceInputNonExistentImpl extends AbstractScriptSourceInput } + @Override + public boolean containsScript(URL url) { + return false; + } + @Override public List extract(Function> extractor) { return Collections.emptyList(); diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ScriptSourceInput.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ScriptSourceInput.java index 19f310b8f2..aca62d85f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ScriptSourceInput.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ScriptSourceInput.java @@ -7,6 +7,7 @@ package org.hibernate.tool.schema.spi; import java.io.Reader; +import java.net.URL; import java.util.List; import java.util.function.Function; @@ -20,5 +21,10 @@ public interface ScriptSourceInput { /** * Allows managed access to the input's Reader, returning a result */ - List extract(Function> extractor); + List extract(Function> extractor); + + default boolean containsScript(URL url) { + return false; + } + }