hibernate/hibernate-orm · error · SchemaManagementException

Writing to script was requested, but no script file was spec

Error message

Writing to script was requested, but no script file was specified

What it means

Schema tooling target resolution: TargetType.SCRIPT was requested in the TargetDescriptor, but targetDescriptor.getScriptTargetOutput() is null - no output file or Writer was configured. Hibernate refuses to 'write the script' to nothing and does not silently fall back to stdout, so the execution aborts before any DDL is generated.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java:170

	public GenerationTarget[] buildGenerationTargets(
			TargetDescriptor targetDescriptor,
			JdbcContext jdbcContext,
			Map<String, Object> options,
			boolean needsAutoCommit) {
		final String scriptDelimiter = getString( HBM2DDL_DELIMITER, options, ";" );

		final var targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ];

		int index = 0;

		if ( targetDescriptor.getTargetTypes().contains( TargetType.STDOUT ) ) {
			targets[index] = buildStdoutTarget( scriptDelimiter );
			index++;
		}

		if ( targetDescriptor.getTargetTypes().contains( TargetType.SCRIPT ) ) {
			if ( targetDescriptor.getScriptTargetOutput() == null ) {
				throw new SchemaManagementException( "Writing to script was requested, but no script file was specified" );
			}
			targets[index] = buildScriptTarget( targetDescriptor, scriptDelimiter );
			index++;
		}

		if ( targetDescriptor.getTargetTypes().contains( TargetType.DATABASE ) ) {
			targets[index] = customTarget == null
					? buildDatabaseTarget( jdbcContext, needsAutoCommit )
					: customTarget;
			index++;
		}

		return targets;
	}

	protected GenerationTarget buildStdoutTarget(String scriptDelimiter) {
		return new GenerationTargetToStdout( scriptDelimiter );
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Configure the output before executing: export.setOutputFile("schema.sql") (or set a Writer/ScriptTargetOutput on the descriptor).
  2. If you only wanted the DDL printed, request TargetType.STDOUT instead of SCRIPT.
  3. Fix custom TargetDescriptor implementations to return a non-null scriptTargetOutput whenever SCRIPT is among the target types.
  4. Cover the schema-generation step with a CI test so config regressions like this fail loudly and early.

Example fix

// before: SCRIPT target requested but no output file configured
SchemaExport export = new SchemaExport(metadata);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, registry);

// after: give the SCRIPT target somewhere to write
SchemaExport export = new SchemaExport(metadata);
export.setOutputFile("target/schema.sql");
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, registry);
Defensive patterns

Strategy: validation

Validate before calling

// Guard the execution config before calling execute
Set<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
String outputFile = "target/schema.sql";
if (targetTypes.contains(TargetType.SCRIPT) && (outputFile == null || outputFile.isBlank())) {
    throw new IllegalStateException("TargetType.SCRIPT requires an output file or ScriptTargetOutput");
}

Try / catch

try {
    export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, registry);
} catch (SchemaManagementException e) {
    if ("Writing to script was requested, but no script file was specified".equals(e.getMessage())) {
        // config bug: call setOutputFile(...) or switch the target to TargetType.STDOUT, then retry
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling SchemaExport/SchemaUpdate-style execution with EnumSet.of(TargetType.SCRIPT) (alone or with DATABASE) while never calling setOutputFile(...) or otherwise providing a ScriptTargetOutput; also custom TargetDescriptor implementations that return null for scriptTargetOutput even though SCRIPT is in the target types.

Common situations: A refactor removes the setOutputFile call; SCRIPT was intended to be STDOUT; programmatic use of HibernateSchemaManagementTool with a hand-built TargetDescriptor; Maven/Gradle schema-generation plugin misconfiguration.

Related errors


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