{"record":{"id":"db30d751ee797b0e","repo":"hibernate/hibernate-orm","slug":"no-provided-connection","errorCode":null,"errorMessage":"No provided connection","messagePattern":"No provided connection","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionProvidedImpl.java","lineNumber":84,"sourceCode":"\t\t}\n\t\tfinally {\n\t\t\tprovidedConnection = null;\n\t\t\tclosed = true;\n\t\t\tCONNECTION_LOGGER.logicalConnectionClosed();\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean isPhysicallyConnected() {\n\t\treturn providedConnection != null;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Connection getPhysicalConnection() {\n\t\terrorIfClosed();\n\t\tif ( providedConnection == null ) {\n\t\t\tthrow new IllegalStateException( \"No provided connection\" );\n\t\t}\n\t\treturn providedConnection;\n\t}\n\n\t@Override\n\tpublic void serialize(ObjectOutputStream oos) throws IOException {\n\t\toos.writeBoolean( closed );\n\t\toos.writeBoolean( initiallyAutoCommit );\n\t}\n\n\tpublic static LogicalConnectionProvidedImpl deserialize(\n\t\t\tObjectInputStream ois) throws IOException, ClassNotFoundException {\n\t\tfinal boolean isClosed = ois.readBoolean();\n\t\tfinal boolean initiallyAutoCommit = ois.readBoolean();\n\t\treturn new LogicalConnectionProvidedImpl( isClosed, initiallyAutoCommit );\n\t}\n\n\t@Override","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionProvidedImpl.java#L66-L102","documentation":"IllegalStateException from LogicalConnectionProvidedImpl.getPhysicalConnection(): the session is open but its user-supplied connection is absent because session.disconnect() detached it earlier. Any JDBC work (query, flush, transaction begin) in this disconnected window fails — the session must be reconnected first.","triggerScenarios":"Running a query, flush, or beginTransaction() on a user-connection session after session.disconnect() but before session.reconnect(newConnection); lazy-loading triggered on a session cached in disconnected state between requests.","commonSituations":"Long-conversation/detached-session patterns (disconnect to release the connection, reconnect on next request) where one code path forgets to reconnect; lazy association traversal on a session that was disconnected for serialization.","solutions":["Reconnect before use: session.reconnect(freshConnection) — only valid for user-supplied-connection sessions","Prefer short-lived sessions opened per unit of work instead of the disconnect/reconnect pattern","Add a fail-fast check (session.isOpen() && session.isConnected()) at a common entry point such as a request filter"],"exampleFix":"// before\nsession.disconnect();\n// ... next request ...\nsession.createQuery(\"from User\", User.class).list(); // IllegalStateException: No provided connection\n\n// after\nsession.disconnect();\n// ... next request ...\ntry (Connection c = dataSource.getConnection()) {\n  session.reconnect(c);\n  return session.createQuery(\"from User\", User.class).list();\n}","handlingStrategy":"validation","validationCode":"// fail fast before using a user-connection session that may be disconnected\nif (!session.isOpen() || !session.isConnected()) {\n  throw new IllegalStateException(\"session must be open and connected before JDBC work\");\n}","typeGuard":"static boolean readyForJdbc(org.hibernate.Session s) {\n  return s != null && s.isOpen() && s.isConnected();\n}","tryCatchPattern":"catch (IllegalStateException e) {\n  // session is open but holds no connection: reconnect with a fresh connection,\n  // or replace with a new session per unit of work\n}","preventionTips":["Always reconnect immediately after disconnect, in the same code path","Add an isOpen() && isConnected() check at request entry points (e.g. a filter)","Prefer short-lived sessions over long-conversation disconnect/reconnect unless required"],"tags":["hibernate","session","disconnected-session","lazy-loading"],"backgroundTag":"session-disconnected","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}