{"record":{"id":"85200f0954566bd1","repo":"hibernate/hibernate-orm","slug":"could-not-build-jdbc-connection-context-to-drop-sc","errorCode":null,"errorMessage":"Could not build JDBC Connection context to drop schema on SessionFactory close","messagePattern":"Could not build JDBC Connection context to drop schema on SessionFactory close","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java","lineNumber":645,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\ttarget.release();\n\t\t\t}\n\t\t}\n\n\t\tprivate static class JdbcContextDelayedDropImpl implements JdbcContext {\n\t\t\tprivate final ServiceRegistry serviceRegistry;\n\t\t\tprivate final JdbcServices jdbcServices;\n\t\t\tprivate final JdbcConnectionAccess jdbcConnectionAccess;\n\n\t\t\tpublic JdbcContextDelayedDropImpl(ServiceRegistry serviceRegistry) {\n\t\t\t\tthis.serviceRegistry = serviceRegistry;\n\t\t\t\tthis.jdbcServices = serviceRegistry.requireService( JdbcServices.class );\n\t\t\t\tthis.jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();\n\t\t\t\tif ( jdbcConnectionAccess == null ) {\n\t\t\t\t\t// todo : log or error?\n\t\t\t\t\tthrow new SchemaManagementException(\n\t\t\t\t\t\t\t\"Could not build JDBC Connection context to drop schema on SessionFactory close\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic JdbcConnectionAccess getJdbcConnectionAccess() {\n\t\t\t\treturn jdbcConnectionAccess;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic Dialect getDialect() {\n\t\t\t\treturn jdbcServices.getJdbcEnvironment().getDialect();\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic SqlStatementLogger getSqlStatementLogger() {\n\t\t\t\treturn jdbcServices.getSqlStatementLogger();","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java#L627-L663","documentation":"With hibernate.hbm2ddl.auto=create-drop the DROP is deferred until SessionFactory close (DelayedDropAction). At close, Hibernate rebuilds a JDBC context via JdbcServices.getBootstrapJdbcConnectionAccess(); if the configured connection provider exposes no bootstrap connection access (null), it cannot obtain a connection to run the drop and throws this SchemaManagementException from the shutdown path. It is a configuration incompatibility, not a network failure.","triggerScenarios":"create-drop combined with a ConnectionProvider whose getBootstrapJdbcConnectionAccess() yields null: multi-tenant setups backed by a MultiTenantConnectionProvider, user-supplied connections, or custom connection providers that only serve tenant/user-scoped connections. The exception is thrown while the SessionFactory is closing, out of the JdbcContextDelayedDropImpl constructor.","commonSituations":"Multi-tenant applications that kept create-drop from a single-tenant prototype; Spring Boot tests wiring a tenant-aware DataSource into hbm2ddl; demos run with externally provided Connections; custom connection providers migrated from Hibernate 5 where this path behaved differently.","solutions":["Switch hibernate.hbm2ddl.auto from create-drop to create or none in environments whose connection provider has no bootstrap JDBC access, and drop schema explicitly when needed.","Run schema generation in a bootstrap phase that uses a plain DataSource/DriverManager-based connection provider, then disable hbm2ddl for the tenant-scoped runtime.","Instead of delayed drop, generate a drop script once (SchemaExport, TargetType.SCRIPT) and apply it from CI/cleanup tooling."],"exampleFix":"// before\n<property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/> <!-- multi-tenant connection provider -->\n\n// after\n<property name=\"hibernate.hbm2ddl.auto\" value=\"none\"/>\n<!-- generate ddl at build time via SchemaExport and manage drops out-of-band -->","handlingStrategy":"validation","validationCode":"JdbcServices jdbc = serviceRegistry.requireService(JdbcServices.class);\nif (jdbc.getBootstrapJdbcConnectionAccess() == null) {\n    // create-drop cannot run its delayed drop here: switch it off before building the factory\n    cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, Action.NONE.getExternalName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    sessionFactory.close();\n} catch (SchemaManagementException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"drop schema on SessionFactory close\")) {\n        // delayed drop could not run; drop the schema out-of-band, then finish shutdown\n    } else { throw e; }\n}","preventionTips":["Never ship create-drop outside isolated tests; prefer explicit scripts.","For multi-tenant or user-supplied-connection setups, keep hbm2ddl disabled and manage schema with migration tooling.","Smoke-test the full open/close lifecycle of the factory in the same configuration you deploy."],"tags":["hibernate","schema-generation","create-drop","session-factory","multi-tenant","connection-provider"],"backgroundTag":"bootstrap-connection-missing","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}