{"record":{"id":"94e2f53c69f962d7","repo":"hibernate/hibernate-orm","slug":"illegally-attempted-to-associate-proxy-wit","errorCode":null,"errorMessage":"Illegally attempted to associate proxy [{}#{}] with two open sessions","messagePattern":"Illegally attempted to associate proxy \\[(.+?)#(.+?)\\] with two open sessions","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":130,"sourceCode":"\t\treturn !initialized;\n\t}\n\n\t@Override\n\tpublic final SharedSessionContractImplementor getSession() {\n\t\treturn session;\n\t}\n\n\t@Override\n\tpublic final void setSession(SharedSessionContractImplementor session) throws HibernateException {\n\t\tif ( session != this.session ) {\n\t\t\t// check for session == null first, since it is less expensive\n\t\t\tif ( session == null ) {\n\t\t\t\tunsetSession();\n\t\t\t}\n\t\t\telse if ( isConnectedToSession() ) {\n\t\t\t\t//TODO: perhaps this should be some other RuntimeException...\n\t\t\t\tCORE_LOGGER.attemptToAssociateProxyWithTwoOpenSessions( entityName, id );\n\t\t\t\tthrow new HibernateException( \"Illegally attempted to associate proxy [\"\n\t\t\t\t\t\t+ entityName + \"#\" + id + \"] with two open sessions\" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// session != null\n\t\t\t\tthis.session = session;\n\t\t\t\tif ( readOnlyBeforeAttachedToSession == null ) {\n\t\t\t\t\t// use the default read-only/modifiable setting\n\t\t\t\t\tsetReadOnly( session.getPersistenceContext().isDefaultReadOnly()\n\t\t\t\t\t\t\t|| !getEntityDescriptor().isMutable() );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// use the read-only/modifiable setting indicated during deserialization\n\t\t\t\t\tsetReadOnly( readOnlyBeforeAttachedToSession );\n\t\t\t\t\treadOnlyBeforeAttachedToSession = null;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L112-L148","documentation":"Error \"Illegally attempted to associate proxy [{}#{}] with two open sessions\" 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 only one open Session; evict or close the first session before attaching to another.","Use merge() to move state between sessions instead of reusing the proxy."],"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"}