{"record":{"id":"53a551bb073e28d1","repo":"hibernate/hibernate-orm","slug":"proxy-for-is-associated-with-a-closed-sess","errorCode":null,"errorMessage":"Proxy for [{}#{}] is associated with a closed session (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)","messagePattern":"Proxy for \\[(.+?)#(.+?)\\] is associated with a closed session \\(the read-only/modifiable setting is only accessible when the proxy is associated with an open session\\)","errorType":"exception","errorClass":"SessionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":401,"sourceCode":"\t */\n\tprotected final Object getTarget() {\n\t\treturn target;\n\t}\n\n\t@Override\n\tpublic final boolean isReadOnlySettingAvailable() {\n\t\treturn session != null && !session.isClosed();\n\t}\n\n\tprivate void errorIfReadOnlySettingNotAvailable() {\n\t\tif ( session == null ) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"Proxy for [\" + entityName + \"#\" + id + \"] is not associated with a session\"\n\t\t\t\t\t\t\t+ \" (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)\"\n\t\t\t);\n\t\t}\n\t\tif ( !session.isOpenOrWaitingForAutoClose() ) {\n\t\t\tthrow new SessionException(\n\t\t\t\t\t\"Proxy for [\" + entityName + \"#\" + id + \"] is associated with a closed session\"\n\t\t\t\t\t\t\t+ \" (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)\"\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override\n\tpublic final boolean isReadOnly() {\n\t\terrorIfReadOnlySettingNotAvailable();\n\t\treturn readOnly;\n\t}\n\n\t@Override\n\tpublic final void setReadOnly(boolean readOnly) {\n\t\terrorIfReadOnlySettingNotAvailable();\n\t\t// only update if readOnly is different from current setting\n\t\tif ( this.readOnly != readOnly ) {\n\t\t\tif ( !getEntityDescriptor().isMutable() && !readOnly ) {","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L383-L419","documentation":"Error \"Proxy for [{}#{}] is associated with a closed session (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)\" 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":["Reopen or obtain a new Session and reload the entity before setting read-only state.","Perform read-only modifications before closing the 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"}