{"record":{"id":"0ad02cc19dfe3c10","repo":"hibernate/hibernate-orm","slug":"proxy-for-is-not-associated-with-a-session","errorCode":null,"errorMessage":"Proxy for [{}#{}] is not associated with a session (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)","messagePattern":"Proxy for \\[(.+?)#(.+?)\\] is not associated with a session \\(the read-only/modifiable setting is only accessible when the proxy is associated with an open session\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":395,"sourceCode":"\t/**\n\t * Getter for property \"target\".\n\t * <p>\n\t * Same as {@link #getImplementation()} except that this method will not force initialization.\n\t *\n\t * @return Value for property \"target\".\n\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","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L377-L413","documentation":"Error \"Proxy for [{}#{}] is not associated with a 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":["Associate the proxy with an open Session before changing read-only state.","Set read-only state on the loaded entity within a session instead."],"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"}