{"record":{"id":"f96142482182c8bd","repo":"hibernate/hibernate-orm","slug":"given-entity-is-not-associated-with-the-persistenc-f96142","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/internal/SessionImpl.java","lineNumber":1837,"sourceCode":"\t\tif ( lazyInitializer != null ) {\n\t\t\tcheckOwnsProxy( lazyInitializer );\n\t\t\tobject = lazyInitializer.getImplementation();\n\t\t}\n\n\t\treturn getEntityEntry( object ).getPersister().getEntityName();\n\t}\n\n\tprivate void checkOwnsProxy(@Nonnull LazyInitializer lazyInitializer) {\n\t\tif ( lazyInitializer.getSession() != this ) {\n\t\t\tthrow new DetachedObjectException( \"Given proxy is not associated with the persistence context\" );\n\t\t}\n\t}\n\n\t@Nonnull\n\tprivate EntityEntry getEntityEntry(@Nonnull Object object) {\n\t\tfinal var entry = persistenceContext.getEntry( object );\n\t\tif ( entry == null ) {\n\t\t\tthrow new UnmanagedObjectException( \"Given entity is not associated with the persistence context\" );\n\t\t}\n\t\treturn entry;\n\t}\n\n\t@Override\n\tpublic String guessEntityName(@Nonnull Object object) {\n\t\tcheckOpenOrWaitingForAutoClose();\n\t\treturn getEntityNameResolver().resolveEntityName( object );\n\t}\n\n\t@Override\n\tpublic void cancelQuery() {\n\t\tcheckOpen();\n\t\tgetJdbcCoordinator().cancelLastQuery();\n\t}\n\n\t@Override\n\tpublic String toString() {","sourceCodeStart":1819,"sourceCodeEnd":1855,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java#L1819-L1855","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/internal/SessionImpl.java:1837 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-attach the entity to the current persistence context using merge() before calling the operation.","Ensure the entity was loaded or persisted by this Session and has not been detached or evicted."],"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"}