{"record":{"id":"1f07843f9956c8e5","repo":"hibernate/hibernate-orm","slug":"user-provided-connection-via-jdbcconnectionaccessp","errorCode":null,"errorMessage":"User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode","messagePattern":"User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/DdlTransactionIsolatorProvidedConnectionImpl.java","lineNumber":46,"sourceCode":"\t\tthis.jdbcContext = jdbcContext;\n\t}\n\n\t@Override\n\tpublic JdbcContext getJdbcContext() {\n\t\treturn jdbcContext;\n\t}\n\n\t@Override\n\tpublic Connection getIsolatedConnection() {\n\t\treturn getIsolatedConnection(true);\n\t}\n\n\t@Override\n\tpublic Connection getIsolatedConnection(boolean autocommit) {\n\t\ttry {\n\t\t\tConnection connection = jdbcContext.getJdbcConnectionAccess().obtainConnection();\n\t\t\tif ( connection.getAutoCommit() != autocommit ) {\n\t\t\t\tthrow new SchemaManagementException( \"User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode\" );\n\t\t\t}\n\t\t\treturn connection;\n\t\t}\n\t\tcatch (SQLException e) {\n\t\t\t// should never happen\n\t\t\tthrow new SchemaManagementException( \"Error accessing user-provided Connection via JdbcConnectionAccessProvidedConnectionImpl\", e );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void release() {\n\t\tfinal var connectionAccess = jdbcContext.getJdbcConnectionAccess();\n\t\tif( !( connectionAccess instanceof JdbcConnectionAccessProvidedConnectionImpl ) ) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\"DdlTransactionIsolatorProvidedConnectionImpl should always use a JdbcConnectionAccessProvidedConnectionImpl\"\n\t\t\t);\n\t\t}\n\t\ttry {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/DdlTransactionIsolatorProvidedConnectionImpl.java#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set connection.setAutoCommit(true) on the provided connection before handing it to the schema tool when it requires autocommit mode.","Or configure the DataSource/pool used for the schema run (e.g. Hikari autoCommit setting) to the mode the tool requests.","Better: let Hibernate manage its own connection/transaction isolator (configure the connection provider) instead of supplying a raw connection for DDL.","If you need transactional DDL, run the statements yourself on your own connection rather than through the schema tool."],"exampleFix":"// before: pool default autoCommit=false, schema tool requires autocommit\nConnection conn = dataSource.getConnection(); // HikariCP default: autoCommit=false\nnew SchemaExport(metadata).execute(targets, Action.BOTH, metadata, registry);\n\n// after: align the mode for the connection handed to the tool\nConnection conn = dataSource.getConnection();\nconn.setAutoCommit(true);\nnew SchemaExport(metadata).execute(targets, Action.BOTH, metadata, registry);","handlingStrategy":"validation","validationCode":"// Before handing a connection to the schema tool, align its auto-commit mode with what the tool requests\nConnection conn = dataSource.getConnection();\nif (!conn.getAutoCommit()) {\n    conn.setAutoCommit(true); // schema tool executes DDL statement-by-statement with autocommit\n}","typeGuard":null,"tryCatchPattern":"try {\n    new SchemaExport(metadata).execute(targets, Action.CREATE, metadata, registry);\n} catch (SchemaManagementException e) {\n    if (\"User-provided Connection via JdbcConnectionAccessProvidedConnectionImpl has wrong auto-commit mode\".equals(e.getMessage())) {\n        // set the requested autoCommit mode on the provided connection and retry once\n    }\n    throw e;\n}","preventionTips":["Dedicate a schema-tooling connection with autocommit enabled rather than reusing transactional pool connections","Check pool defaults (HikariCP defaults to autoCommit=false) before feeding connections to hbm2ddl","Prefer letting Hibernate manage its own connection provider for DDL instead of user-supplied connections"],"tags":["hibernate","schema-management","connection","autocommit","jdbc"],"backgroundTag":"connection-auto-commit-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}