hibernate/hibernate-orm · error · SchemaManagementException
Unable to open specified script target file [
Error message
Unable to open specified script target file [
What it means
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).
Source
Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromFile.java:72
@Override
public int read(char[] cbuf, int off, int len) {
return -1;
}
@Override
public void close() {
}
};
}
try {
final var fileInputStream = new FileInputStream( file );
return charsetName != null
? new InputStreamReader( fileInputStream, charsetName )
: new InputStreamReader( fileInputStream );
}
catch (IOException e) {
throw new SchemaManagementException(
"Unable to open specified script target file [" + file + "] for reading",
e
);
}
}
@Override
protected void releaseReader(Reader reader) {
try {
reader.close();
}
catch (IOException e) {
LOG.warn( "Unable to close file reader for generation script source" );
}
}
@Override
public boolean containsScript(URL url) {View on GitHub (pinned to fad1729dce)
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.
Example fix
# before: unreadable/wrong path jakarta.persistence.sql-load-script-source=conf/import.sql # conf/ is a directory # after: regular readable file, absolute where cwd is uncertain jakarta.persistence.sql-load-script-source=/opt/app/config/import.sql
Defensive patterns
Strategy: validation
Validate before calling
Path p = Path.of( scriptPath );
if ( !Files.isRegularFile( p ) || !Files.isReadable( p ) ) {
throw new IllegalStateException( "Import script missing or unreadable: " + p.toAbsolutePath() );
}
if ( charsetName != null && !Charset.isSupported( charsetName ) ) {
throw new IllegalStateException( "Unsupported charset for import script: " + charsetName );
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error resolving legacy import resource : %s
- Unable to open specified script source url [
- Error performing schema management [persistence unit: {}]
- Attempt to resolve foreign key metadata from JDBC metadata f
- Passed table name cannot be null
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/a320849d1b563872.
Report an issue: GitHub.