{"record":{"id":"e109fba45c9ff5cd","repo":"hibernate/hibernate-orm","slug":"could-not-initialize-proxy-session-was-c","errorCode":null,"errorMessage":"Could not initialize proxy [{}#{}] - session was closed or disconnected","messagePattern":"Could not initialize proxy \\[(.+?)#(.+?)\\] - session was closed or disconnected","errorType":"exception","errorClass":"LazyInitializationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":262,"sourceCode":"\t\t\t\t\t\tsession.close();\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\tCORE_LOGGER.unableToCLoseTempSession();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t+ entityName + \"#\" + id + \"]: \" + e.getMessage() );\n\t\t\t}\n\t\t}\n\t\telse if ( session.isOpenOrWaitingForAutoClose() && session.isConnected() ) {\n\t\t\ttarget = immediateLoad( session );\n\t\t\tinitialized = true;\n\t\t\tcheckTargetState( session );\n\t\t}\n\t\telse {\n\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t+ entityName + \"#\" + id + \"] - session was closed or disconnected\" );\n\t\t}\n\t}\n\n\tprivate Object immediateLoad(SharedSessionContractImplementor session) {\n\t\tif ( temporalIdentifier != null ) {\n\t\t\tfinal var influencers = session.getLoadQueryInfluencers();\n\t\t\tfinal Object previous = influencers.getTemporalIdentifier();\n\t\t\tinfluencers.setTemporalIdentifier( temporalIdentifier );\n\t\t\ttry {\n\t\t\t\treturn session.immediateLoad( entityName, id );\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tinfluencers.setTemporalIdentifier( previous );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn session.immediateLoad( entityName, id );","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L244-L280","documentation":"Error \"Could not initialize proxy [{}#{}] - session was closed or disconnected\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A lazy proxy is accessed outside the lifecycle of its owning Hibernate Session.","commonSituations":"LazyInitializationException-style failures when rendering entities after the transaction/Session closed, common in web views and serialization.","solutions":["Initialize the proxy while the session is open and connected.","Catch LazyInitializationException and reload within an active session."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}