{"record":{"id":"ec7108d38e970759","repo":"hibernate/hibernate-orm","slug":"writing-to-script-was-requested-but-no-script-fil","errorCode":null,"errorMessage":"Writing to script was requested, but no script file was specified","messagePattern":"Writing to script was requested, but no script file was specified","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java","lineNumber":170,"sourceCode":"\tpublic GenerationTarget[] buildGenerationTargets(\n\t\t\tTargetDescriptor targetDescriptor,\n\t\t\tJdbcContext jdbcContext,\n\t\t\tMap<String, Object> options,\n\t\t\tboolean needsAutoCommit) {\n\t\tfinal String scriptDelimiter = getString( HBM2DDL_DELIMITER, options, \";\" );\n\n\t\tfinal var targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ];\n\n\t\tint index = 0;\n\n\t\tif ( targetDescriptor.getTargetTypes().contains( TargetType.STDOUT ) ) {\n\t\t\ttargets[index] = buildStdoutTarget( scriptDelimiter );\n\t\t\tindex++;\n\t\t}\n\n\t\tif ( targetDescriptor.getTargetTypes().contains( TargetType.SCRIPT ) ) {\n\t\t\tif ( targetDescriptor.getScriptTargetOutput() == null ) {\n\t\t\t\tthrow new SchemaManagementException( \"Writing to script was requested, but no script file was specified\" );\n\t\t\t}\n\t\t\ttargets[index] = buildScriptTarget( targetDescriptor, scriptDelimiter );\n\t\t\tindex++;\n\t\t}\n\n\t\tif ( targetDescriptor.getTargetTypes().contains( TargetType.DATABASE ) ) {\n\t\t\ttargets[index] = customTarget == null\n\t\t\t\t\t? buildDatabaseTarget( jdbcContext, needsAutoCommit )\n\t\t\t\t\t: customTarget;\n\t\t\tindex++;\n\t\t}\n\n\t\treturn targets;\n\t}\n\n\tprotected GenerationTarget buildStdoutTarget(String scriptDelimiter) {\n\t\treturn new GenerationTargetToStdout( scriptDelimiter );\n\t}","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java#L152-L188","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: SCRIPT target requested but no output file configured\nSchemaExport export = new SchemaExport(metadata);\nexport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, registry);\n\n// after: give the SCRIPT target somewhere to write\nSchemaExport export = new SchemaExport(metadata);\nexport.setOutputFile(\"target/schema.sql\");\nexport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, registry);","handlingStrategy":"validation","validationCode":"// Guard the execution config before calling execute\nSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);\nString outputFile = \"target/schema.sql\";\nif (targetTypes.contains(TargetType.SCRIPT) && (outputFile == null || outputFile.isBlank())) {\n    throw new IllegalStateException(\"TargetType.SCRIPT requires an output file or ScriptTargetOutput\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, registry);\n} catch (SchemaManagementException e) {\n    if (\"Writing to script was requested, but no script file was specified\".equals(e.getMessage())) {\n        // config bug: call setOutputFile(...) or switch the target to TargetType.STDOUT, then retry\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["hibernate","schema-management","schema-export","script-target","configuration"],"backgroundTag":"missing-configuration-value","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}