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

  1. Check existence, readability and that the path is a regular file: Files.isRegularFile(path) && Files.isReadable(path) before startup.
  2. Fix permissions (chmod a+r) or correct the path to point at the actual script file, not its directory.
  3. Verify the charset setting names a supported charset (use UTF-8 unless you know better).
  4. 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

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


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