HHH-17594 HHH-17665 Fix proxy narrowing for delayed subtype entities

This commit is contained in:
Marco Belladelli 2024-01-05 11:30:46 +01:00 committed by Christian Beikov
parent 652da4205f
commit ff0b535435
3 changed files with 21 additions and 6 deletions

View File

@ -898,9 +898,14 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override
public Object proxyFor(EntityHolder holder) throws HibernateException {
return proxyFor( holder, holder.getDescriptor() );
}
@Override
public Object proxyFor(EntityHolder holder, EntityPersister persister) {
final Object proxy = holder.getProxy();
return proxy != null && holder.getDescriptor().hasProxy()
? narrowProxy( proxy, holder.getDescriptor(), holder.getEntityKey(), holder.getEntity() )
return proxy != null && persister.hasProxy()
? narrowProxy( proxy, persister, holder.getEntityKey(), holder.getEntity() )
: holder.getEntity();
}

View File

@ -348,10 +348,20 @@ public interface PersistenceContext {
Object proxyFor(Object impl);
/**
* Return the existing proxy associated with the given {@code EntityKey}, or the
* argument (the entity associated with the key) if no proxy exists.
* (slower than the form above)
* Return the existing {@linkplain EntityHolder#getProxy() proxy} associated with
* the given {@link EntityHolder}, or the {@linkplain EntityHolder#getEntity() entity}
* if no proxy exists.
*/
Object proxyFor(EntityHolder holder, EntityPersister persister);
/**
* Return the existing {@linkplain EntityHolder#getProxy() proxy} associated with
* the given {@link EntityHolder}, or the {@linkplain EntityHolder#getEntity() entity}
* if it contains no proxy.
*
* @deprecated Use {@link #proxyFor(EntityHolder, EntityPersister)} instead.
*/
@Deprecated( forRemoval = true )
Object proxyFor(EntityHolder holder);
/**

View File

@ -103,7 +103,7 @@ public class EntityDelayedFetchInitializer extends AbstractFetchParentAccess imp
final EntityHolder holder = persistenceContext.getEntityHolder( entityKey );
if ( holder != null && holder.getEntity() != null ) {
entityInstance = persistenceContext.proxyFor( holder );
entityInstance = persistenceContext.proxyFor( holder, concreteDescriptor );
}
}
if ( entityInstance == null ) {