hibernate/hibernate-orm · error · UnmanagedObjectException
Given entity is not associated with the persistence context
Error message
Given entity is not associated with the persistence context
What it means
Error "Given entity is not associated with the persistence context" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:1837
if ( lazyInitializer != null ) {
checkOwnsProxy( lazyInitializer );
object = lazyInitializer.getImplementation();
}
return getEntityEntry( object ).getPersister().getEntityName();
}
private void checkOwnsProxy(@Nonnull LazyInitializer lazyInitializer) {
if ( lazyInitializer.getSession() != this ) {
throw new DetachedObjectException( "Given proxy is not associated with the persistence context" );
}
}
@Nonnull
private EntityEntry getEntityEntry(@Nonnull Object object) {
final var entry = persistenceContext.getEntry( object );
if ( entry == null ) {
throw new UnmanagedObjectException( "Given entity is not associated with the persistence context" );
}
return entry;
}
@Override
public String guessEntityName(@Nonnull Object object) {
checkOpenOrWaitingForAutoClose();
return getEntityNameResolver().resolveEntityName( object );
}
@Override
public void cancelQuery() {
checkOpen();
getJdbcCoordinator().cancelLastQuery();
}
@Override
public String toString() {View on GitHub (pinned to fad1729dce)
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.
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:1837 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/f96142482182c8bd.
Report an issue: GitHub.