{"record":{"id":"671730020ba5396d","repo":"hibernate/hibernate-orm","slug":"given-entity-is-not-associated-with-the-persistenc","errorCode":null,"errorMessage":"Given entity is not associated with the persistence context","messagePattern":"Given entity is not associated with the persistence context","errorType":"exception","errorClass":"UnmanagedObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java","lineNumber":1704,"sourceCode":"\n\tprivate void clearNullProperties() {\n\t\tnullAssociations = null;\n\t}\n\n\t@Override\n\tpublic boolean isReadOnly(Object entityOrProxy) {\n\t\tif ( entityOrProxy == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Entity may not be null\" );\n\t\t}\n\n\t\tfinal var lazyInitializer = extractLazyInitializer( entityOrProxy );\n\t\tif ( lazyInitializer != null ) {\n\t\t\treturn lazyInitializer.isReadOnly();\n\t\t}\n\t\telse {\n\t\t\tfinal var ee = getEntry( entityOrProxy );\n\t\t\tif ( ee == null ) {\n\t\t\t\tthrow new UnmanagedObjectException( \"Given entity is not associated with the persistence context\" );\n\t\t\t}\n\t\t\treturn ee.isReadOnly();\n\t\t}\n\t}\n\n\t@Override\n\tpublic void setReadOnly(Object object, boolean readOnly) {\n\t\tif ( object == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Entity may not be null\" );\n\t\t}\n\t\tif ( isReadOnly( object ) != readOnly ) {\n\t\t\tfinal var lazyInitializer = extractLazyInitializer( object );\n\t\t\tif ( lazyInitializer != null ) {\n\t\t\t\tsetProxyReadOnly( lazyInitializer, readOnly );\n\t\t\t\tif ( !lazyInitializer.isUninitialized() ) {\n\t\t\t\t\tsetEntityReadOnly( lazyInitializer.getImplementation(), readOnly );\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":1686,"sourceCodeEnd":1722,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java#L1686-L1722","documentation":"Error \"Given entity is not associated with the persistence context\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:1704 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Load or attach the entity to the current persistence context before the operation","Check session.contains(entity) before invoking context-bound operations"],"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"}