Skip to content

Commit

Permalink
HHH-17594 HHH-17665 Fix proxy narrowing for delayed subtype entities
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel authored and beikov committed Jan 30, 2024
1 parent 8ed1e1c commit 8be3a1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,14 @@ public Object proxyFor(Object impl) throws HibernateException {

@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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,20 @@ EntityEntry addEntry(
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);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
final EntityKey entityKey = new EntityKey( identifier, concreteDescriptor );
final EntityHolder holder = persistenceContext.getEntityHolder( entityKey );
if ( holder != null && holder.getEntity() != null ) {
entityInstance = persistenceContext.proxyFor( holder );
entityInstance = persistenceContext.proxyFor( holder, concreteDescriptor );
}
// For primary key based mappings we only use bytecode-laziness if the attribute is optional,
// because the non-optionality implies that it is safe to have a proxy
Expand Down

0 comments on commit 8be3a1d

Please sign in to comment.