hibernate/hibernate-orm · error · SchemaManagementException

User-provided Connection via…

Error message

User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode

What it means

Schema tooling running on a user-provided Connection (DdlTransactionIsolatorProvidedConnectionImpl) obtained the connection and found its auto-commit mode different from the mode the tool requires (getIsolatedConnection(autocommit) - GenerationTargetToDatabase passes its needsAutoCommit flag here). Hibernate executes DDL statement-by-statement on that connection and requires the mode to match exactly, so it refuses to proceed with a mismatched connection.

Solutions

  1. Set connection.setAutoCommit(true) on the provided connection before handing it to the schema tool when it requires autocommit mode.
  2. Or configure the DataSource/pool used for the schema run (e.g. Hikari autoCommit setting) to the mode the tool requests.
  3. Better: let Hibernate manage its own connection/transaction isolator (configure the connection provider) instead of supplying a raw connection for DDL.
  4. If you need transactional DDL, run the statements yourself on your own connection rather than through the schema tool.

Example fix

// before: pool default autoCommit=false, schema tool requires autocommit
Connection conn = dataSource.getConnection(); // HikariCP default: autoCommit=false
new SchemaExport(metadata).execute(targets, Action.BOTH, metadata, registry);

// after: align the mode for the connection handed to the tool
Connection conn = dataSource.getConnection();
conn.setAutoCommit(true);
new SchemaExport(metadata).execute(targets, Action.BOTH, metadata, registry);
Defensive patterns

Strategy: validation

Validate before calling

// Before handing a connection to the schema tool, align its auto-commit mode with what the tool requests
Connection conn = dataSource.getConnection();
if (!conn.getAutoCommit()) {
    conn.setAutoCommit(true); // schema tool executes DDL statement-by-statement with autocommit
}

Try / catch

try {
    new SchemaExport(metadata).execute(targets, Action.CREATE, metadata, registry);
} catch (SchemaManagementException e) {
    if ("User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode".equals(e.getMessage())) {
        // set the requested autoCommit mode on the provided connection and retry once
    }
    throw e;
}

Prevention

When it happens

Trigger: Running SchemaExport/SchemaUpdate against TargetType.DATABASE with a ServiceRegistry whose ConnectionProvider hands out an external connection (JdbcConnectionAccessProvidedConnectionImpl), while that connection has the opposite auto-commit mode - typically a pooled DataSource connection with autoCommit=false (HikariCP default) when the tool needs autocommit=true, or a driver/pool that ignores setAutoCommit.

Common situations: Passing a transaction-ready pooled connection into schema export during integration tests; app-managed transactions with autocommit off; deliberately setting autocommit(false) for atomic DDL and then handing the same connection to Hibernate's schema tool.

Related errors


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/internal/DdlTransactionIsolatorProvidedConnectionImpl.java:46

		this.jdbcContext = jdbcContext;
	}

	@Override
	public JdbcContext getJdbcContext() {
		return jdbcContext;
	}

	@Override
	public Connection getIsolatedConnection() {
		return getIsolatedConnection(true);
	}

	@Override
	public Connection getIsolatedConnection(boolean autocommit) {
		try {
			Connection connection = jdbcContext.getJdbcConnectionAccess().obtainConnection();
			if ( connection.getAutoCommit() != autocommit ) {
				throw new SchemaManagementException( "User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode" );
			}
			return connection;
		}
		catch (SQLException e) {
			// should never happen
			throw new SchemaManagementException( "Error accessing user-provided Connection via JdbcConnectionAccessProvidedConnectionImpl", e );
		}
	}

	@Override
	public void release() {
		final var connectionAccess = jdbcContext.getJdbcConnectionAccess();
		if( !( connectionAccess instanceof JdbcConnectionAccessProvidedConnectionImpl ) ) {
			throw new IllegalStateException(
				"DdlTransactionIsolatorProvidedConnectionImpl should always use a JdbcConnectionAccessProvidedConnectionImpl"
			);
		}
		try {

View on GitHub (pinned to fad1729dce)