Search in sources :

Example 6 with FetchStrategy

use of org.hibernate.engine.FetchStrategy in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method handleAssociationAttribute.

protected boolean handleAssociationAttribute(AssociationAttributeDefinition attributeDefinition) {
    // todo : this seems to not be correct for one-to-one
    final FetchStrategy fetchStrategy = determineFetchStrategy(attributeDefinition);
    final ExpandingFetchSource currentSource = currentSource();
    currentSource.validateFetchPlan(fetchStrategy, attributeDefinition);
    final AssociationAttributeDefinition.AssociationNature nature = attributeDefinition.getAssociationNature();
    if (nature == AssociationAttributeDefinition.AssociationNature.ANY) {
        // for ANY mappings we need to build a Fetch:
        // 1) fetch type is SELECT
        // 2) (because the fetch cannot be a JOIN...) do not push it to the stack
        // regardless of the fetch style, build the fetch
        currentSource.buildAnyAttributeFetch(attributeDefinition, fetchStrategy);
        return false;
    } else if (nature == AssociationAttributeDefinition.AssociationNature.ENTITY) {
        // regardless of the fetch style, build the fetch
        EntityFetch fetch = currentSource.buildEntityAttributeFetch(attributeDefinition, fetchStrategy);
        if (FetchStrategyHelper.isJoinFetched(fetchStrategy)) {
            // only push to the stack if join fetched
            pushToStack((ExpandingFetchSource) fetch);
            return true;
        } else {
            return false;
        }
    } else {
        // Collection
        // regardless of the fetch style, build the fetch
        CollectionAttributeFetch fetch = currentSource.buildCollectionAttributeFetch(attributeDefinition, fetchStrategy);
        if (FetchStrategyHelper.isJoinFetched(fetchStrategy)) {
            // only push to the stack if join fetched
            pushToCollectionStack(fetch);
            return true;
        } else {
            return false;
        }
    }
}
Also used : EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) CollectionAttributeFetch(org.hibernate.loader.plan.spi.CollectionAttributeFetch) FetchStrategy(org.hibernate.engine.FetchStrategy) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) AssociationAttributeDefinition(org.hibernate.persister.walking.spi.AssociationAttributeDefinition)

Aggregations

FetchStrategy (org.hibernate.engine.FetchStrategy)6 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 FetchStyle (org.hibernate.engine.FetchStyle)2 ExpandingFetchSource (org.hibernate.loader.plan.build.spi.ExpandingFetchSource)2 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)2 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)2 Iterator (java.util.Iterator)1 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)1 GraphNodeImplementor (org.hibernate.graph.spi.GraphNodeImplementor)1 PropertyPath (org.hibernate.loader.PropertyPath)1 CollectionAttributeFetch (org.hibernate.loader.plan.spi.CollectionAttributeFetch)1 EntityFetch (org.hibernate.loader.plan.spi.EntityFetch)1 FetchSource (org.hibernate.loader.plan.spi.FetchSource)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1 Joinable (org.hibernate.persister.entity.Joinable)1 OuterJoinLoadable (org.hibernate.persister.entity.OuterJoinLoadable)1 AttributeDefinition (org.hibernate.persister.walking.spi.AttributeDefinition)1 AttributeSource (org.hibernate.persister.walking.spi.AttributeSource)1 CompositionDefinition (org.hibernate.persister.walking.spi.CompositionDefinition)1 WalkingException (org.hibernate.persister.walking.spi.WalkingException)1