{"record":{"id":"d18a065e4cda5ec2","repo":"hibernate/hibernate-orm","slug":"entity-is-not-associated-with-the-session","errorCode":null,"errorMessage":"entity is not associated with the session: {}","messagePattern":"entity is not associated with the session: (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java","lineNumber":1569,"sourceCode":"\n\t\treturn conjunction;\n\t}\n\n\t@Override\n\tpublic Object initializeLazyProperty(String fieldName, Object entity, SharedSessionContractImplementor session) {\n\t\treturn hasCollections() && getPropertyTypes()[getPropertyIndex( fieldName )] instanceof CollectionType collectionType\n\t\t\t\t? initializedLazyCollection( fieldName, entity, collectionType, session )\n\t\t\t\t: initializedLazyField( fieldName, entity, session );\n\t}\n\n\tprivate Object initializedLazyField(\n\t\t\tString fieldName,\n\t\t\tObject entity,\n\t\t\tSharedSessionContractImplementor session) {\n\t\tfinal Object id = session.getContextEntityIdentifier( entity );\n\t\tfinal var entry = session.getPersistenceContext().getEntry( entity );\n\t\tif ( entry == null ) {\n\t\t\tthrow new HibernateException( \"entity is not associated with the session: \" + id );\n\t\t}\n\n\t\tif ( CORE_LOGGER.isTraceEnabled() ) {\n\t\t\tCORE_LOGGER.initializingLazyPropertiesOf(\n\t\t\t\t\tinfoString( this, id, getFactory() ),\n\t\t\t\t\tfieldName\n\t\t\t);\n\t\t}\n\n\t\t// attempt to read it from second-level cache\n\t\tif ( session.getCacheMode().isGetEnabled()\n\t\t\t\t&& isLazyPropertiesCacheable() ) {\n\t\t\tfinal Object cachedValue = initializeLazyFieldFromCache( fieldName, entity, session, id, entry );\n\t\t\tif ( cachedValue != UNFETCHED_PROPERTY ) {\n\t\t\t\t// The following should be redundant, since the setter should have set this already.\n\t\t\t\t// interceptor.attributeInitialized(fieldName);\n\n\t\t\t\t// NOTE EARLY EXIT!!!","sourceCodeStart":1551,"sourceCodeEnd":1587,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java#L1551-L1587","documentation":"Error \"entity is not associated with the session: {}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when an operation requires the entity to be managed by the current session but the instance is detached or transient.","commonSituations":"See trigger scenarios.","solutions":["Re-attach the entity with merge() or load it in the current session before performing the operation.","Do not pass detached entities to operations requiring a managed instance."],"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"}