{"record":{"id":"87d3aa7953c4c94f","repo":"hibernate/hibernate-orm","slug":"could-not-initialize-proxy-the-owning-se","errorCode":null,"errorMessage":"Could not initialize proxy [{}#{}] - the owning session was closed","messagePattern":"Could not initialize proxy \\[(.+?)#(.+?)\\] - the owning session was closed","errorType":"exception","errorClass":"LazyInitializationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":182,"sourceCode":"\t\tprepareForPossibleLoadingOutsideTransaction();\n\t\tsession = null;\n\t\treadOnly = false;\n\t\treadOnlyBeforeAttachedToSession = null;\n\t}\n\n\t@Override\n\tpublic final void initialize() throws HibernateException {\n\t\tif ( !initialized ) {\n\t\t\ttry {\n\t\t\t\tif ( allowLoadOutsideTransaction ) {\n\t\t\t\t\tpermissiveInitialization();\n\t\t\t\t}\n\t\t\t\telse if ( session == null ) {\n\t\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t\t+ entityName + \"#\" + id + \"] - no session\" );\n\t\t\t\t}\n\t\t\t\telse if ( !session.isOpenOrWaitingForAutoClose() ) {\n\t\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t\t+ entityName + \"#\" + id + \"] - the owning session was closed\" );\n\t\t\t\t}\n\t\t\t\telse if ( !session.isConnected() ) {\n\t\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t\t+ entityName + \"#\" + id + \"] - the owning session is disconnected\" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttarget = immediateLoad( session );\n\t\t\t\t\tinitialized = true;\n\t\t\t\t\tcheckTargetState( session );\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tif ( session != null && !session.isTransactionInProgress() ) {\n\t\t\t\t\tsession.getJdbcCoordinator().afterTransaction();\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L164-L200","documentation":"Error \"Could not initialize proxy [{}#{}] - the owning session was closed\" 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 before closing the owning Session.","Reattach the entity to a new Session via merge/load before accessing lazy state."],"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"}