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
- Configure the output before executing: export.setOutputFile("schema.sql") (or set a Writer/ScriptTargetOutput on the descriptor).
- If you only wanted the DDL printed, request TargetType.STDOUT instead of SCRIPT.
- Fix custom TargetDescriptor implementations to return a non-null scriptTargetOutput whenever SCRIPT is among the target types.
- 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
- Assert script-output configuration in a small unit test covering the schema-generation step
- Use TargetType.STDOUT for local DDL previews; SCRIPT only with an explicit output path
- For custom TargetDescriptor implementations, return a non-null ScriptTargetOutput whenever SCRIPT is requested
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
- Illegal state : writer null - not prepared
- No create schema syntax supported by " + getClass().getName(
- No drop schema syntax supported by " + getClass().getName()
- The {storageEngine} storage engine is not supported
- Audit graph mutation plan used with non-graph action queue
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ec7108d38e970759.
Report an issue: GitHub.