HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
This commit is contained in:
parent
c607e30051
commit
9e1acbac41
|
@ -29,6 +29,7 @@ import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext;
|
|||
import org.hibernate.loader.plan2.spi.CollectionFetchableElement;
|
||||
import org.hibernate.loader.plan2.spi.CollectionFetchableIndex;
|
||||
import org.hibernate.loader.plan2.spi.CollectionReference;
|
||||
import org.hibernate.loader.plan2.spi.FetchSource;
|
||||
import org.hibernate.loader.plan2.spi.Join;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
|
|
@ -584,28 +584,32 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
|||
return; // nothing to do
|
||||
}
|
||||
|
||||
final AssociationKey associationKey = attributeDefinition.getAssociationKey();
|
||||
|
||||
// go ahead and build the bidirectional fetch
|
||||
if ( attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY ) {
|
||||
final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister();
|
||||
final AssociationKey currentEntityReferenceAssociationKey =
|
||||
new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() );
|
||||
final Joinable fetchSourceEntityPersister =
|
||||
(Joinable) registeredFetchSource( attributeDefinition.getAssociationKey() ).resolveEntityReference().getEntityPersister();
|
||||
final AssociationKey fetchSourceEntityReferenceAssociationKey =
|
||||
new AssociationKey( fetchSourceEntityPersister.getTableName(), fetchSourceEntityPersister.getKeyColumnNames() );
|
||||
if ( ! attributeDefinition.getAssociationKey().equals( currentEntityReferenceAssociationKey ) &&
|
||||
! attributeDefinition.getAssociationKey().equals( fetchSourceEntityReferenceAssociationKey ) ) {
|
||||
// if associationKey is equal to currentEntityReferenceAssociationKey
|
||||
// that means that the current EntityPersister has a single primary key attribute
|
||||
// (i.e., derived attribute) which is mapped by attributeDefinition.
|
||||
// This is not a bidirectional association.
|
||||
// TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
|
||||
// it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
|
||||
// deal with this???
|
||||
if ( ! associationKey.equals( currentEntityReferenceAssociationKey ) ) {
|
||||
currentSource().buildBidirectionalEntityFetch(
|
||||
attributeDefinition,
|
||||
fetchStrategy,
|
||||
fetchedAssociationKeySourceMap.get( attributeDefinition.getAssociationKey() ).resolveEntityReference(),
|
||||
registeredFetchSource( associationKey ).resolveEntityReference(),
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Collection
|
||||
currentSource().buildCollectionFetch( attributeDefinition, fetchStrategy, this );
|
||||
//currentSource().buildCollectionFetch( attributeDefinition, fetchStrategy, this );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jboss.logging.Logger;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.loader.PropertyPath;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -261,6 +262,15 @@ public class MetamodelGraphWalker {
|
|||
visitAttributes( elementDefinition.toCompositeElementDefinition() );
|
||||
}
|
||||
else if ( elementDefinition.getType().isEntityType() ) {
|
||||
if ( ! collectionDefinition.getCollectionPersister().isOneToMany() ) {
|
||||
final QueryableCollection queryableCollection = (QueryableCollection) collectionDefinition.getCollectionPersister();
|
||||
addAssociationKey(
|
||||
new AssociationKey(
|
||||
queryableCollection.getTableName(),
|
||||
queryableCollection.getElementColumnNames()
|
||||
)
|
||||
);
|
||||
}
|
||||
visitEntityDefinition( elementDefinition.toEntityDefinition() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue