hibernate/hibernate-orm · error · SchemaManagementException

Schema generation configuration indicated to include CREATE

Error message

Schema generation configuration indicated to include CREATE scripts, but no script was specified

What it means

Hibernate throws this SchemaManagementException at SessionFactory bootstrap when JPA schema generation is told to build the database schema partly or wholly from DDL scripts, but no script location was provided. SchemaManagementToolCoordinator.sourceType() derives a SourceType from jakarta.persistence.schema-generation.create-source (or drop-source); when that is 'script', 'metadata-then-script' or 'script-then-metadata' while the matching create-script-source/drop-script-source setting is null, buildDatabaseTargetDescriptor() (SchemaManagementToolCoordinator.java:338) fails fast instead of silently generating nothing.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementToolCoordinator.java:339

			}
		}
	}

	private static SourceType sourceType(Map<?, ?> configuration, SettingSelector settingSelector, Object scriptSourceSetting) {
		return SourceType.interpret( settingSelector.getSourceTypeSetting( configuration ),
				scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA );
	}

	private static JpaTargetAndSourceDescriptor buildDatabaseTargetDescriptor(
			Map<?,?> configuration,
			SettingSelector settingSelector,
			ServiceRegistry serviceRegistry) {

		final Object scriptSourceSetting = settingSelector.getScriptSourceSetting( configuration );
		final var sourceType = sourceType( configuration, settingSelector, scriptSourceSetting );
		final boolean includesScripts = sourceType != SourceType.METADATA;
		if ( includesScripts && scriptSourceSetting == null ) {
			throw new SchemaManagementException(
					"Schema generation configuration indicated to include CREATE scripts, but no script was specified"
			);
		}

		final var scriptSourceInput =
				includesScripts
						? interpretScriptSourceSetting( scriptSourceSetting,
								serviceRegistry.getService( ClassLoaderService.class ),
								(String) configuration.get( HBM2DDL_CHARSET_NAME ) )
						: null;

		return new JpaTargetAndSourceDescriptor() {
			@Override
			public EnumSet<TargetType> getTargetTypes() {
				return EnumSet.of( TargetType.DATABASE );
			}

			@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add jakarta.persistence.schema-generation.create-script-source (or drop-script-source) pointing to a loadable script, e.g. 'create.sql' (classpath resource) or 'file:/opt/db/create.sql'.
  2. If you only want metadata-driven DDL, set jakarta.persistence.schema-generation.create-source=metadata (or simply remove the create-source/drop-source entry).
  3. Verify the exact key names: it is 'create-script-source' and 'drop-script-source', not 'create-source-script'; confirm jakarta.* spelling on Hibernate 6+.
  4. If a property placeholder supplies the script path, check it resolves to a non-null value at bootstrap time.

Example fix

// persistence.xml (before)
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="jakarta.persistence.schema-generation.drop-source" value="script"/>
<!-- missing: drop-script-source -->

// persistence.xml (after)
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="jakarta.persistence.schema-generation.drop-source" value="script"/>
<property name="jakarta.persistence.schema-generation.drop-script-source" value="drop.sql"/>
Defensive patterns

Strategy: validation

Validate before calling

// Validate JPA schema-gen settings before building the EMF
boolean sourceIncludesScripts = Stream.of("script", "metadata-then-script", "script-then-metadata")
    .anyMatch(v -> v.equalsIgnoreCase((String) props.getOrDefault(
        "jakarta.persistence.schema-generation.create-source", "")))
    || Stream.of("script", "metadata-then-script", "script-then-metadata")
    .anyMatch(v -> v.equalsIgnoreCase((String) props.getOrDefault(
        "jakarta.persistence.schema-generation.drop-source", "")));
if (sourceIncludesScripts
        && props.get("jakarta.persistence.schema-generation.create-script-source") == null
        && props.get("jakarta.persistence.schema-generation.drop-script-source") == null) {
    throw new IllegalStateException(
        "create-source/drop-source includes scripts but no *-script-source is configured");
}

Try / catch

try {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu", props);
} catch (PersistenceException e) {
    if (e.getCause() instanceof SchemaManagementException sme
            && sme.getMessage().contains("no script was specified")) {
        throw new ConfigurationException("Fix schema-generation script-source settings", sme);
    }
    throw e;
}

Prevention

When it happens

Trigger: Setting jakarta.persistence.schema-generation.database.action to create/create-drop/drop (or hibernate.hbm2ddl.auto equivalent) together with jakarta.persistence.schema-generation.create-source=script (or drop-source=script, metadata-then-script, script-then-metadata) while omitting jakarta.persistence.schema-generation.create-script-source (or drop-script-source). Legacy keys hibernate.hbm2ddl.create_source / hibernate.hbm2ddl.create_script_source are read too, so the same mix with old-style keys also triggers it.

Common situations: Copy-pasting a partial JPA 2.1 schema-generation example into persistence.xml; migrating javax.persistence.* to jakarta.persistence.* and misspelling the new key so the script-source lookup silently misses; a CI property file defining create-source in one profile but the script path in another; typos like 'create-source-script' instead of 'create-script-source'.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/1ac1cfa57c4212fc. Report an issue: GitHub.