hibernate/hibernate-orm · error · SessionException
proxies cannot be fetched by a stateless session
Error message
proxies cannot be fetched by a stateless session
What it means
Error "proxies cannot be fetched by a stateless session" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1364
for ( Object entity : entities ) {
doRefresh( bestGuessEntityName( entity ), entity, LockMode.NONE );
}
}
catch ( MappingException e ) {
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
throw getExceptionConverter().convert( e );
}
finally {
afterOperation();
}
}
@Override
public Object immediateLoad(@Nonnull String entityName, @Nonnull Object id) {
if ( getPersistenceContextInternal().isLoadFinished() ) {
throw new SessionException( "proxies cannot be fetched by a stateless session" );
}
// unless we are still in the process of handling a top-level load
return get( entityName, id );
}
@Override
public void initializeCollection(@Nonnull PersistentCollection<?> collection, boolean writing) {
checkOpen();
final var persistenceContext = getPersistenceContextInternal();
final var ce = persistenceContext.getCollectionEntry( collection );
if ( ce == null ) {
throw new HibernateException( "no entry for collection" );
}
if ( !collection.wasInitialized() ) {
final var loadedPersister = ce.getLoadedPersister();
final Object loadedKey = ce.getLoadedKey();
if ( loadedPersister == null ) {
throw new AssertionFailure( "collection entry has no loaded persister" );View on GitHub (pinned to fad1729dce)
Solutions
- Use a regular Session if you need proxy/lazy fetching; stateless sessions do not support proxies.
- Fetch the entity eagerly via the stateless session API instead of obtaining a proxy.
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1364 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/914349144c5ada01.
Report an issue: GitHub.