Skip to content

Commit 287b920

Browse files
dreab8yrodiere
authored andcommitted
HHH-19098 Disable implicit loading of the default import script
1 parent 1b13fd3 commit 287b920

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/SchemaToolingSettings.java

+8
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ public interface SchemaToolingSettings {
391391
@Deprecated
392392
String HBM2DDL_IMPORT_FILES = "hibernate.hbm2ddl.import_files";
393393

394+
/**
395+
* Specifies if the default {@code /import.sql} script file should not be executed
396+
* when {@link #HBM2DDL_IMPORT_FILES} is not specified and {@value #HBM2DDL_AUTO} is set to {@code create} or {@code create-drop}.
397+
*
398+
* The default value is {@code false}.
399+
*/
400+
String HBM2DDL_SKIP_DEFAULT_IMPORT_FILE = "hibernate.hbm2ddl.skip_default_import_file";
401+
394402
/**
395403
* Specifies whether to automatically create also the database schema/catalog.
396404
* The default is false.

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_IMPORT_FILES;
6161
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE;
6262
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE;
63+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_SKIP_DEFAULT_IMPORT_FILE;
6364
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
65+
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
6466
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
6567
import static org.hibernate.tool.schema.internal.Helper.applyScript;
6668
import static org.hibernate.tool.schema.internal.Helper.applySqlStrings;
@@ -597,11 +599,24 @@ private void applyImportSources(
597599
commandExtractor,
598600
dialect,
599601
formatter,
600-
hasDefaultImportFileScriptBeenExecuted ? "" : DEFAULT_IMPORT_FILE,
602+
hasDefaultImportFileScriptBeenExecuted ? "" : getDefaultImportFile( options ),
601603
targets
602604
);
603605
}
604606

607+
private String getDefaultImportFile(ExecutionOptions options) {
608+
if ( skipDefaultFileImport( options ) ) {
609+
return "";
610+
}
611+
else {
612+
return DEFAULT_IMPORT_FILE;
613+
}
614+
}
615+
616+
private static boolean skipDefaultFileImport(ExecutionOptions options) {
617+
return getBoolean( HBM2DDL_SKIP_DEFAULT_IMPORT_FILE, options.getConfigurationValues(), false );
618+
}
619+
605620
/**
606621
* In principle, we should format the commands in the import script if the
607622
* {@code format} parameter is {@code true}, and since it's supposed to be
@@ -642,16 +657,19 @@ private boolean applyImportScript(
642657
formatter,
643658
targets
644659
);
645-
return containsDefaultImportFile( importScriptInput );
660+
return containsDefaultImportFile( importScriptInput, options );
646661
}
647662
else {
648663
return false;
649664
}
650665
}
651666

652-
private boolean containsDefaultImportFile(ScriptSourceInput importScriptInput) {
667+
private boolean containsDefaultImportFile(ScriptSourceInput importScriptInput,ExecutionOptions options ) {
668+
if ( skipDefaultFileImport( options ) ) {
669+
return false;
670+
}
653671
final URL defaultImportFileUrl = getClassLoaderService().locateResource( DEFAULT_IMPORT_FILE );
654-
return defaultImportFileUrl != null && importScriptInput.containsScript(defaultImportFileUrl);
672+
return defaultImportFileUrl != null && importScriptInput.containsScript( defaultImportFileUrl );
655673
}
656674

657675
/**

0 commit comments

Comments
 (0)