{"record":{"id":"40bfc3218f7b11e1","repo":"hibernate/hibernate-orm","slug":"cannot-make-proxy-for-immutable-entity-mod","errorCode":null,"errorMessage":"Cannot make proxy [{}#{}] for immutable entity modifiable","messagePattern":"Cannot make proxy \\[(.+?)#(.+?)\\] for immutable entity modifiable","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":420,"sourceCode":"\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 ) {\n\t\t\t\tthrow new IllegalStateException( \"Cannot make proxy [\" + entityName + \"#\" + id + \"] for immutable entity modifiable\" );\n\t\t\t}\n\t\t\tthis.readOnly = readOnly;\n\t\t\tif ( initialized ) {\n\t\t\t\tfinal var key = generateEntityKeyOrNull( getInternalIdentifier(), session, getEntityName() );\n\t\t\t\tif ( key != null ) {\n\t\t\t\t\tfinal var persistenceContext = session.getPersistenceContext();\n\t\t\t\t\tif ( persistenceContext.containsEntity( key ) ) {\n\t\t\t\t\t\tpersistenceContext.setReadOnly( target, readOnly );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the read-only/modifiable setting that should be put in effect when it is\n\t * attached to a session.\n\t * <p>","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L402-L438","documentation":"Error \"Cannot make proxy [{}#{}] for immutable entity modifiable\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate API is violated.","commonSituations":"Occurs when application code or configuration does not satisfy the documented contract of the API being called.","solutions":["Do not attempt to make proxies of @Immutable entities modifiable.","Remove the @Immutable annotation if mutation is required."],"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"}