{"record":{"id":"a320849d1b563872","repo":"hibernate/hibernate-orm","slug":"unable-to-open-specified-script-target-file","errorCode":null,"errorMessage":"Unable to open specified script target file [","messagePattern":"Unable to open specified script target file \\[","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java","lineNumber":72,"sourceCode":"\t\t\t\t@Override\n\t\t\t\tpublic int read(char[] cbuf, int off, int len) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic void close() {\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\ttry {\n\t\t\tfinal var fileInputStream = new FileInputStream( file );\n\t\t\treturn charsetName != null\n\t\t\t\t\t? new InputStreamReader( fileInputStream, charsetName )\n\t\t\t\t\t: new InputStreamReader( fileInputStream );\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new SchemaManagementException(\n\t\t\t\t\t\"Unable to open specified script target file [\" + file + \"] for reading\",\n\t\t\t\t\te\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override\n\tprotected void releaseReader(Reader reader) {\n\t\ttry {\n\t\t\treader.close();\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tLOG.warn( \"Unable to close file reader for generation script source\" );\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean containsScript(URL url) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java#L54-L90","documentation":"Raised while preparing the reader for a script SOURCE (import/load script) addressed as a plain File — the message saying 'script target file' is a long-standing wording quirk, this class reads scripts, it does not write them. Note the nuance in this Hibernate version: a merely missing file only logs a warning and yields an empty script; this SchemaManagementException fires when opening the stream actually throws IOException. Typical real causes: the path is a directory, the file exists but is unreadable (permissions), or the configured charset name is unsupported (InputStreamReader throws UnsupportedEncodingException, an IOException).","triggerScenarios":"jakarta.persistence.sql-load-script-source / javax.persistence.sql-load-script-source or hibernate.hbm2ddl.import_files resolving to a File that cannot be opened: unreadable permissions, path denotes a directory, or an invalid charsetName passed to the reader constructor.","commonSituations":"Script file deployed without read permission (containers, hardened hosts), path pointing at a directory by mistake, exotic/misspelled charset name configured for import script reading, file present in the build but stripped from the packaged artifact.","solutions":["Check existence, readability and that the path is a regular file: Files.isRegularFile(path) && Files.isReadable(path) before startup.","Fix permissions (chmod a+r) or correct the path to point at the actual script file, not its directory.","Verify the charset setting names a supported charset (use UTF-8 unless you know better).","If the file genuinely may be absent, note this version only warns — an exception here means something else (permissions/charset), so inspect the chained IOException."],"exampleFix":"# before: unreadable/wrong path\njakarta.persistence.sql-load-script-source=conf/import.sql   # conf/ is a directory\n\n# after: regular readable file, absolute where cwd is uncertain\njakarta.persistence.sql-load-script-source=/opt/app/config/import.sql","handlingStrategy":"validation","validationCode":"Path p = Path.of( scriptPath );\nif ( !Files.isRegularFile( p ) || !Files.isReadable( p ) ) {\n    throw new IllegalStateException( \"Import script missing or unreadable: \" + p.toAbsolutePath() );\n}\nif ( charsetName != null && !Charset.isSupported( charsetName ) ) {\n    throw new IllegalStateException( \"Unsupported charset for import script: \" + charsetName );\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve script paths to absolute paths at startup (log them once) so cwd changes cannot break them.","Add a build-time check that packaged artifacts contain the script and are world-readable.","Use UTF-8 for import scripts and configure the charset explicitly to match.","Remember: a merely missing file only logs a WARN in this version — an exception here means permissions/charset, investigate the chained IOException."],"tags":["hibernate","schema-management","import-script","file-io","charset"],"backgroundTag":"sql-script-file-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}