hibernate/hibernate-orm · error · LazyInitializationException

could not retrieve real entity class [{}#{}] - no Session

Error message

could not retrieve real entity class [{}#{}] - no Session

What it means

Error "could not retrieve real entity class [{}#{}] - no Session" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/proxy/pojo/BasicLazyInitializer.java:120

			return replacement;
		}
		else {
			return getTarget();
		}
	}

	@Override
	public final Class<?> getPersistentClass() {
		return persistentClass;
	}

	@Override
	public Class<?> getImplementationClass() {
		if ( !isUninitialized() ) {
			return getImplementation().getClass();
		}
		else if ( getSession() == null ) {
			throw new LazyInitializationException( "could not retrieve real entity class ["
							+ getEntityName() + "#" + getInternalIdentifier() + "] - no Session" );
		}
		else {
			return getEntityDescriptor().hasSubclasses()
					? getImplementation().getClass()
					: persistentClass;
		}
	}

}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Resolve the entity class while the proxy is still attached to an open Session.
  2. Reload the entity in a new session when needed.

When it happens

Trigger: A runtime precondition of the Hibernate API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/d58da60d30e9aa64. Report an issue: GitHub.