HHH-15986 Eager Bidirectional association, initializing an HibernateProxy should associate to the circular association the HibernateProxy itself

This commit is contained in:
Andrea Boriero 2023-01-04 11:43:15 +01:00 committed by Andrea Boriero
parent e0ff430936
commit 303da7fca8
1 changed files with 7 additions and 5 deletions

View File

@ -155,8 +155,7 @@ public class CircularBiDirectionalFetchImpl implements BiDirectionalFetch {
final EntityPersister entityPersister = (EntityPersister) fetchable.asAttributeMapping().getMappedType(); final EntityPersister entityPersister = (EntityPersister) fetchable.asAttributeMapping().getMappedType();
final CollectionKey collectionKey = circ.resolveCollectionKey( rowProcessingState ); final CollectionKey collectionKey = circ.resolveCollectionKey( rowProcessingState );
final Object key = collectionKey.getKey(); final Object key = collectionKey.getKey();
final SharedSessionContractImplementor session = rowProcessingState.getJdbcValuesSourceProcessingState() final SharedSessionContractImplementor session = rowProcessingState.getSession();
.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContext(); final PersistenceContext persistenceContext = session.getPersistenceContext();
if ( fetchable.getReferencedPropertyName() != null ) { if ( fetchable.getReferencedPropertyName() != null ) {
return loadByUniqueKey( entityPersister, key, session, persistenceContext ); return loadByUniqueKey( entityPersister, key, session, persistenceContext );
@ -182,12 +181,15 @@ public class CircularBiDirectionalFetchImpl implements BiDirectionalFetch {
final Object initializedInstance = initializer.getInitializedInstance(); final Object initializedInstance = initializer.getInitializedInstance();
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( initializedInstance ); final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( initializedInstance );
if ( lazyInitializer != null ) { if ( lazyInitializer != null ) {
if ( initializedInstance.getClass().isAssignableFrom( javaType.getJavaTypeClass() ) ) { final Class<?> concreteProxyClass = initializer.getConcreteDescriptor().getConcreteProxyClass();
if ( concreteProxyClass.isInstance( initializedInstance ) ) {
return initializedInstance; return initializedInstance;
} }
else {
initializer.initializeInstance( rowProcessingState ); initializer.initializeInstance( rowProcessingState );
return lazyInitializer.getImplementation(); return lazyInitializer.getImplementation();
} }
}
return initializedInstance; return initializedInstance;
} }