{"record":{"id":"e5846e03ece284b5","repo":"hibernate/hibernate-orm","slug":"given-proxy-is-not-associated-with-the-persistence","errorCode":null,"errorMessage":"Given proxy is not associated with the persistence context","messagePattern":"Given proxy is not associated with the persistence context","errorType":"exception","errorClass":"DetachedObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java","lineNumber":1829,"sourceCode":"//\t\tcheckTransactionSynchStatus();\n\n\t\t//noinspection ConstantValue\n\t\tif ( object == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Entity may not be null\" );\n\t\t}\n\n\t\tfinal var lazyInitializer = extractLazyInitializer( object );\n\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","sourceCodeStart":1811,"sourceCodeEnd":1847,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java#L1811-L1847","documentation":"Error \"Given proxy 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:1829 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only pass proxies obtained from this same Session; reload the entity with the current session if it was loaded elsewhere.","Attach the proxy first (e.g. merge) before performing the operation on it."],"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"}