HHH-18872 Resolve concrete entity name when initializing lazy to-ones

This commit is contained in:
Marco Belladelli 2024-11-22 11:42:26 +01:00
parent 3cfa7c7b00
commit d723ff01d8
1 changed files with 7 additions and 2 deletions

View File

@ -767,8 +767,13 @@ public abstract class EntityType extends AbstractType implements AssociationType
getAssociatedEntityPersister( session.getFactory() )
.isInstrumented();
final Object proxyOrEntity =
session.internalLoad( getAssociatedEntityName(), id, isEager( overridingEager ), isNullable() );
final boolean isEager = isEager( overridingEager );
// If the association is lazy, retrieve the concrete type if required
final String entityName = isEager ? getAssociatedEntityName()
: getAssociatedEntityPersister( session.getFactory() ).resolveConcreteProxyTypeForId( id, session )
.getEntityName();
final Object proxyOrEntity = session.internalLoad( entityName, id, isEager, isNullable() );
final LazyInitializer lazyInitializer = extractLazyInitializer( proxyOrEntity );
if ( lazyInitializer != null ) {