hibernate/hibernate-orm · error · LazyInitializationException
Could not retrieve real entity name [{}#{}] - no session
Error message
Could not retrieve real entity name [{}#{}] - no session What it means
Error "Could not retrieve real entity name [{}#{}] - no session" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java:367
return target;
}
@Override
public final void setImplementation(Object target) {
this.target = target;
initialized = true;
}
@Override
public final Object getImplementation(SharedSessionContractImplementor session) throws HibernateException {
final var entityKey = generateEntityKeyOrNull( getInternalIdentifier(), session, getEntityName() );
return entityKey == null ? null : session.getPersistenceContext().getEntity( entityKey );
}
@Override
public String getImplementationEntityName() {
if ( session == null ) {
throw new LazyInitializationException( "Could not retrieve real entity name ["
+ entityName + "#" + id + "] - no session" );
}
if ( getEntityDescriptor().hasSubclasses() ) {
initialize();
return getFactory().bestGuessEntityName( target );
}
return entityName;
}
/**
* Getter for property "target".
* <p>
* Same as {@link #getImplementation()} except that this method will not force initialization.
*
* @return Value for property "target".
*/
protected final Object getTarget() {
return target;View on GitHub (pinned to fad1729dce)
Solutions
- Resolve the entity name while a Session is available.
- Avoid calling getEntityName on detached proxies.
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/5d773e4ed1b6f5a9.
Report an issue: GitHub.