Skip to content

Commit ff0b535

Browse files
mbelladebeikov
authored andcommitted
HHH-17594 HHH-17665 Fix proxy narrowing for delayed subtype entities
1 parent 652da42 commit ff0b535

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,14 @@ public Object proxyFor(Object impl) throws HibernateException {
898898

899899
@Override
900900
public Object proxyFor(EntityHolder holder) throws HibernateException {
901+
return proxyFor( holder, holder.getDescriptor() );
902+
}
903+
904+
@Override
905+
public Object proxyFor(EntityHolder holder, EntityPersister persister) {
901906
final Object proxy = holder.getProxy();
902-
return proxy != null && holder.getDescriptor().hasProxy()
903-
? narrowProxy( proxy, holder.getDescriptor(), holder.getEntityKey(), holder.getEntity() )
907+
return proxy != null && persister.hasProxy()
908+
? narrowProxy( proxy, persister, holder.getEntityKey(), holder.getEntity() )
904909
: holder.getEntity();
905910
}
906911

hibernate-core/src/main/java/org/hibernate/engine/spi/PersistenceContext.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,20 @@ EntityEntry addEntry(
348348
Object proxyFor(Object impl);
349349

350350
/**
351-
* Return the existing proxy associated with the given {@code EntityKey}, or the
352-
* argument (the entity associated with the key) if no proxy exists.
353-
* (slower than the form above)
351+
* Return the existing {@linkplain EntityHolder#getProxy() proxy} associated with
352+
* the given {@link EntityHolder}, or the {@linkplain EntityHolder#getEntity() entity}
353+
* if no proxy exists.
354+
*/
355+
Object proxyFor(EntityHolder holder, EntityPersister persister);
356+
357+
/**
358+
* Return the existing {@linkplain EntityHolder#getProxy() proxy} associated with
359+
* the given {@link EntityHolder}, or the {@linkplain EntityHolder#getEntity() entity}
360+
* if it contains no proxy.
361+
*
362+
* @deprecated Use {@link #proxyFor(EntityHolder, EntityPersister)} instead.
354363
*/
364+
@Deprecated( forRemoval = true )
355365
Object proxyFor(EntityHolder holder);
356366

357367
/**

hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
103103

104104
final EntityHolder holder = persistenceContext.getEntityHolder( entityKey );
105105
if ( holder != null && holder.getEntity() != null ) {
106-
entityInstance = persistenceContext.proxyFor( holder );
106+
entityInstance = persistenceContext.proxyFor( holder, concreteDescriptor );
107107
}
108108
}
109109
if ( entityInstance == null ) {

0 commit comments

Comments
 (0)