Search in sources :

Example 1 with CollectionPart

use of org.hibernate.metamodel.mapping.CollectionPart in project hibernate-orm by hibernate.

the class ToOneAttributeMapping method createTableGroupJoin.

@Override
public TableGroupJoin createTableGroupJoin(NavigablePath navigablePath, TableGroup lhs, String explicitSourceAlias, SqlAstJoinType requestedJoinType, boolean fetched, boolean addsPredicate, SqlAliasBaseGenerator aliasBaseGenerator, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
    // This is vital for the map key property check that comes next
    assert !(lhs instanceof PluralTableGroup);
    TableGroup parentTableGroup = lhs;
    ModelPartContainer parentContainer = lhs.getModelPart();
    StringBuilder embeddablePathSb = null;
    // Traverse up embeddable table groups until we find a table group for a collection part
    while (!(parentContainer instanceof CollectionPart)) {
        if (parentContainer instanceof EmbeddableValuedModelPart) {
            if (embeddablePathSb == null) {
                embeddablePathSb = new StringBuilder();
            }
            embeddablePathSb.insert(0, parentContainer.getPartName() + ".");
            parentTableGroup = fromClauseAccess.findTableGroup(parentTableGroup.getNavigablePath().getParent());
            parentContainer = parentTableGroup.getModelPart();
        } else {
            break;
        }
    }
    final SqlAstJoinType joinType;
    if (requestedJoinType == null) {
        joinType = SqlAstJoinType.INNER;
    } else {
        joinType = requestedJoinType;
    }
    // we check if this attribute is the map key property to reuse the existing index table group
    if (CollectionPart.Nature.ELEMENT.getName().equals(parentTableGroup.getNavigablePath().getUnaliasedLocalName()) && !addsPredicate && (joinType == SqlAstJoinType.INNER || joinType == SqlAstJoinType.LEFT)) {
        final PluralTableGroup pluralTableGroup = (PluralTableGroup) fromClauseAccess.findTableGroup(parentTableGroup.getNavigablePath().getParent());
        final String indexPropertyName = pluralTableGroup.getModelPart().getIndexMetadata().getIndexPropertyName();
        final String pathName;
        if (embeddablePathSb != null) {
            pathName = embeddablePathSb.append(getAttributeName()).toString();
        } else {
            pathName = getAttributeName();
        }
        if (pathName.equals(indexPropertyName)) {
            final TableGroup indexTableGroup = pluralTableGroup.getIndexTableGroup();
            // If this is the map key property, we can reuse the index table group
            initializeIfNeeded(lhs, requestedJoinType, indexTableGroup);
            return new TableGroupJoin(navigablePath, joinType, new MappedByTableGroup(navigablePath, this, indexTableGroup, fetched, pluralTableGroup, (np, tableExpression) -> {
                if (!canUseParentTableGroup) {
                    return false;
                }
                NavigablePath path = np.getParent();
                // Fast path
                if (path != null && navigablePath.equals(path)) {
                    return targetKeyPropertyNames.contains(np.getUnaliasedLocalName()) && identifyingColumnsTableExpression.equals(tableExpression);
                }
                final StringBuilder sb = new StringBuilder(np.getFullPath().length());
                sb.append(np.getUnaliasedLocalName());
                while (path != null && !navigablePath.equals(path)) {
                    sb.insert(0, '.');
                    sb.insert(0, path.getUnaliasedLocalName());
                    path = path.getParent();
                }
                return path != null && navigablePath.equals(path) && targetKeyPropertyNames.contains(sb.toString()) && identifyingColumnsTableExpression.equals(tableExpression);
            }), null);
        }
    }
    final LazyTableGroup lazyTableGroup = createRootTableGroupJoin(navigablePath, lhs, explicitSourceAlias, requestedJoinType, fetched, null, aliasBaseGenerator, sqlExpressionResolver, fromClauseAccess, creationContext);
    final TableGroupJoin join = new TableGroupJoin(navigablePath, joinType, lazyTableGroup, null);
    final TableReference lhsTableReference = lhs.resolveTableReference(navigablePath, identifyingColumnsTableExpression);
    lazyTableGroup.setTableGroupInitializerCallback(tableGroup -> join.applyPredicate(foreignKeyDescriptor.generateJoinPredicate(sideNature == ForeignKeyDescriptor.Nature.TARGET ? lhsTableReference : tableGroup.getPrimaryTableReference(), sideNature == ForeignKeyDescriptor.Nature.TARGET ? tableGroup.getPrimaryTableReference() : lhsTableReference, sqlExpressionResolver, creationContext)));
    return join;
}
Also used : Arrays(java.util.Arrays) EntityPersister(org.hibernate.persister.entity.EntityPersister) Property(org.hibernate.mapping.Property) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) TreatedNavigablePath(org.hibernate.query.spi.TreatedNavigablePath) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess) EntityResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultImpl) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ToOne(org.hibernate.mapping.ToOne) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EntityAssociationMapping(org.hibernate.metamodel.mapping.EntityAssociationMapping) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) PersistentClass(org.hibernate.mapping.PersistentClass) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) Join(org.hibernate.mapping.Join) TableGroupProducer(org.hibernate.sql.ast.tree.from.TableGroupProducer) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityDelayedResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityDelayedResultImpl) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) EntityValuedFetchable(org.hibernate.sql.results.graph.entity.EntityValuedFetchable) EntityDelayedFetchImpl(org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchImpl) MappedByTableGroup(org.hibernate.sql.ast.tree.from.MappedByTableGroup) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) OneToOne(org.hibernate.mapping.OneToOne) VirtualModelPart(org.hibernate.metamodel.mapping.VirtualModelPart) NavigablePath(org.hibernate.query.spi.NavigablePath) StringHelper(org.hibernate.internal.util.StringHelper) DomainResult(org.hibernate.sql.results.graph.DomainResult) Set(java.util.Set) Value(org.hibernate.mapping.Value) Collection(org.hibernate.mapping.Collection) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) ArrayHelper(org.hibernate.internal.util.collections.ArrayHelper) CircularBiDirectionalFetchImpl(org.hibernate.sql.results.internal.domain.CircularBiDirectionalFetchImpl) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) CircularFetchImpl(org.hibernate.sql.results.internal.domain.CircularFetchImpl) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) SqlAliasBaseGenerator(org.hibernate.sql.ast.spi.SqlAliasBaseGenerator) EntityFetchSelectImpl(org.hibernate.sql.results.graph.entity.internal.EntityFetchSelectImpl) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) EntityResultJoinedSubclassImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultJoinedSubclassImpl) SqlAliasStemHelper(org.hibernate.sql.ast.spi.SqlAliasStemHelper) EmbeddedComponentType(org.hibernate.type.EmbeddedComponentType) EntityType(org.hibernate.type.EntityType) Clause(org.hibernate.sql.ast.Clause) TableReference(org.hibernate.sql.ast.tree.from.TableReference) HashSet(java.util.HashSet) ModelPart(org.hibernate.metamodel.mapping.ModelPart) ComponentType(org.hibernate.type.ComponentType) CompositeType(org.hibernate.type.CompositeType) BiConsumer(java.util.function.BiConsumer) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) ManyToOne(org.hibernate.mapping.ManyToOne) LockMode(org.hibernate.LockMode) AssociationKey(org.hibernate.metamodel.mapping.AssociationKey) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Iterator(java.util.Iterator) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer) EmbeddableValuedFetchable(org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable) StateArrayContributorMetadataAccess(org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess) Fetch(org.hibernate.sql.results.graph.Fetch) Consumer(java.util.function.Consumer) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) EntityFetch(org.hibernate.sql.results.graph.entity.EntityFetch) FetchStyle(org.hibernate.engine.FetchStyle) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) Selectable(org.hibernate.mapping.Selectable) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) Collections(java.util.Collections) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) EntityFetchJoinedImpl(org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl) Type(org.hibernate.type.Type) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) MappedByTableGroup(org.hibernate.sql.ast.tree.from.MappedByTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) TreatedNavigablePath(org.hibernate.query.spi.TreatedNavigablePath) NavigablePath(org.hibernate.query.spi.NavigablePath) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) MappedByTableGroup(org.hibernate.sql.ast.tree.from.MappedByTableGroup) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) TableReference(org.hibernate.sql.ast.tree.from.TableReference) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer)

Example 2 with CollectionPart

use of org.hibernate.metamodel.mapping.CollectionPart in project hibernate-orm by hibernate.

the class MappingModelCreationHelper method interpretMapKey.

private static CollectionPart interpretMapKey(Collection bootValueMapping, CollectionPersister collectionDescriptor, String tableExpression, String sqlAliasStem, Dialect dialect, MappingModelCreationProcess creationProcess) {
    assert bootValueMapping instanceof IndexedCollection;
    final IndexedCollection indexedCollection = (IndexedCollection) bootValueMapping;
    final Value bootMapKeyDescriptor = indexedCollection.getIndex();
    if (bootMapKeyDescriptor instanceof BasicValue) {
        final BasicValue basicValue = (BasicValue) bootMapKeyDescriptor;
        final SelectableMapping selectableMapping = SelectableMappingImpl.from(tableExpression, basicValue.getSelectables().get(0), basicValue.resolve().getJdbcMapping(), dialect, creationProcess.getSqmFunctionRegistry());
        return new BasicValuedCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, basicValue.resolve().getValueConverter(), selectableMapping);
    }
    if (bootMapKeyDescriptor instanceof Component) {
        final Component component = (Component) bootMapKeyDescriptor;
        final CompositeType compositeType = (CompositeType) component.getType();
        final EmbeddableMappingTypeImpl mappingType = EmbeddableMappingTypeImpl.from(component, compositeType, inflightDescriptor -> new EmbeddedCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, inflightDescriptor, // parent-injection
        component.getParentProperty(), tableExpression, sqlAliasStem), creationProcess);
        return (CollectionPart) mappingType.getEmbeddedValueMapping();
    }
    if (bootMapKeyDescriptor instanceof OneToMany || bootMapKeyDescriptor instanceof ToOne) {
        final EntityType indexEntityType = (EntityType) collectionDescriptor.getIndexType();
        final EntityPersister associatedEntity = creationProcess.getEntityPersister(indexEntityType.getAssociatedEntityName());
        final EntityCollectionPart indexDescriptor = new EntityCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, bootMapKeyDescriptor, associatedEntity, creationProcess);
        creationProcess.registerInitializationCallback("PluralAttributeMapping( " + bootValueMapping.getRole() + ") - index descriptor", () -> {
            indexDescriptor.finishInitialization(collectionDescriptor, bootValueMapping, indexEntityType.getRHSUniqueKeyPropertyName(), creationProcess);
            return true;
        });
        return indexDescriptor;
    }
    throw new NotYetImplementedFor6Exception("Support for plural attributes with index type [" + bootMapKeyDescriptor + "] not yet implemented");
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) OneToMany(org.hibernate.mapping.OneToMany) BasicValue(org.hibernate.mapping.BasicValue) EntityType(org.hibernate.type.EntityType) SimpleValue(org.hibernate.mapping.SimpleValue) Value(org.hibernate.mapping.Value) BasicValue(org.hibernate.mapping.BasicValue) SortableValue(org.hibernate.mapping.SortableValue) KeyValue(org.hibernate.mapping.KeyValue) ToOne(org.hibernate.mapping.ToOne) OneToOne(org.hibernate.mapping.OneToOne) ManyToOne(org.hibernate.mapping.ManyToOne) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) Component(org.hibernate.mapping.Component) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) IndexedCollection(org.hibernate.mapping.IndexedCollection) CompositeType(org.hibernate.type.CompositeType)

Example 3 with CollectionPart

use of org.hibernate.metamodel.mapping.CollectionPart in project hibernate-orm by hibernate.

the class StandardEntityGraphTraversalStateImpl method traverse.

@Override
public TraversalResult traverse(FetchParent fetchParent, Fetchable fetchable, boolean exploreKeySubgraph) {
    assert !(fetchable instanceof CollectionPart);
    final GraphImplementor previousContextRoot = currentGraphContext;
    AttributeNodeImplementor attributeNode = null;
    if (appliesTo(fetchParent)) {
        attributeNode = currentGraphContext.findAttributeNode(fetchable.getFetchableName());
    }
    currentGraphContext = null;
    FetchTiming fetchTiming = null;
    boolean joined = false;
    if (attributeNode != null) {
        fetchTiming = FetchTiming.IMMEDIATE;
        joined = true;
        final Map<Class<?>, SubGraphImplementor> subgraphMap;
        final Class<?> subgraphMapKey;
        if (fetchable instanceof PluralAttributeMapping) {
            PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
            assert exploreKeySubgraph && isJpaMapCollectionType(pluralAttributeMapping) || !exploreKeySubgraph && !isJpaMapCollectionType(pluralAttributeMapping);
            if (exploreKeySubgraph) {
                subgraphMap = attributeNode.getKeySubGraphMap();
                subgraphMapKey = getEntityCollectionPartJavaClass(pluralAttributeMapping.getIndexDescriptor());
            } else {
                subgraphMap = attributeNode.getSubGraphMap();
                subgraphMapKey = getEntityCollectionPartJavaClass(pluralAttributeMapping.getElementDescriptor());
            }
        } else {
            assert !exploreKeySubgraph;
            subgraphMap = attributeNode.getSubGraphMap();
            subgraphMapKey = fetchable.getJavaType().getJavaTypeClass();
        }
        if (subgraphMap != null && subgraphMapKey != null) {
            currentGraphContext = subgraphMap.get(subgraphMapKey);
        }
    }
    if (fetchTiming == null) {
        if (graphSemantic == GraphSemantic.FETCH) {
            fetchTiming = FetchTiming.DELAYED;
            joined = false;
        } else {
            fetchTiming = fetchable.getMappedFetchOptions().getTiming();
            joined = fetchable.getMappedFetchOptions().getStyle() == FetchStyle.JOIN;
        }
    }
    return new TraversalResult(previousContextRoot, fetchTiming, joined);
}
Also used : AttributeNodeImplementor(org.hibernate.graph.spi.AttributeNodeImplementor) FetchTiming(org.hibernate.engine.FetchTiming) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) RootGraphImplementor(org.hibernate.graph.spi.RootGraphImplementor) GraphImplementor(org.hibernate.graph.spi.GraphImplementor) SubGraphImplementor(org.hibernate.graph.spi.SubGraphImplementor) SubGraphImplementor(org.hibernate.graph.spi.SubGraphImplementor)

Example 4 with CollectionPart

use of org.hibernate.metamodel.mapping.CollectionPart in project hibernate-orm by hibernate.

the class PluralAttributePath method resolvePathPart.

@Override
public DomainPath resolvePathPart(String name, String identifier, boolean isTerminal, TranslationContext translationContext) {
    final ModelPart subPart = pluralAttributeMapping.findSubPart(name, null);
    if (subPart != null) {
        if (subPart instanceof CollectionPart) {
            return new CollectionPartPath(this, (CollectionPart) subPart);
        }
        if (subPart instanceof EmbeddableValuedModelPart) {
            return new DomainPathContinuation(navigablePath.append(name), this, subPart);
        }
        if (subPart instanceof ToOneAttributeMapping) {
            return new FkDomainPathContinuation(navigablePath.append(name), this, (ToOneAttributeMapping) subPart);
        }
        // leaf case:
        final CollectionPartPath elementPath = new CollectionPartPath(this, pluralAttributeMapping.getElementDescriptor());
        return (DomainPath) elementPath.resolvePathPart(name, identifier, isTerminal, translationContext);
    }
    if (pluralAttributeMapping.getElementDescriptor() instanceof EmbeddableValuedModelPart) {
        final EmbeddableValuedModelPart elementDescriptor = (EmbeddableValuedModelPart) pluralAttributeMapping.getElementDescriptor();
        final ModelPart elementSubPart = elementDescriptor.findSubPart(name, null);
        if (elementSubPart != null) {
            // create the CollectionSubPath to use as the `lhs` for the element sub-path
            final CollectionPartPath elementPath = new CollectionPartPath(this, (CollectionPart) elementDescriptor);
            return new DomainPathContinuation(elementPath.getNavigablePath().append(name), this, elementSubPart);
        }
    }
    if (pluralAttributeMapping.getIndexDescriptor() instanceof EmbeddableValuedModelPart) {
        final EmbeddableValuedModelPart indexDescriptor = (EmbeddableValuedModelPart) pluralAttributeMapping.getIndexDescriptor();
        final ModelPart indexSubPart = indexDescriptor.findSubPart(name, null);
        if (indexSubPart != null) {
            // create the CollectionSubPath to use as the `lhs` for the element sub-path
            final CollectionPartPath indexPath = new CollectionPartPath(this, (CollectionPart) indexDescriptor);
            return new DomainPathContinuation(indexPath.getNavigablePath().append(name), this, indexSubPart);
        }
    }
    return null;
}
Also used : AbstractDomainPath(org.hibernate.metamodel.mapping.internal.AbstractDomainPath) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart)

Example 5 with CollectionPart

use of org.hibernate.metamodel.mapping.CollectionPart in project hibernate-orm by hibernate.

the class SqmMappingModelHelper method resolveSqmPath.

private static ModelPart resolveSqmPath(SqmPath<?> sqmPath, MappingMetamodel domainModel, Function<NavigablePath, TableGroup> tableGroupLocator) {
    if (sqmPath instanceof SqmTreatedPath) {
        final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath;
        final EntityDomainType treatTargetType = treatedPath.getTreatTarget();
        return domainModel.findEntityDescriptor(treatTargetType.getHibernateEntityName());
    }
    // see if the LHS is treated
    if (sqmPath.getLhs() instanceof SqmTreatedPath) {
        final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath.getLhs();
        final EntityDomainType treatTargetType = treatedPath.getTreatTarget();
        final EntityPersister container = domainModel.findEntityDescriptor(treatTargetType.getHibernateEntityName());
        return container.findSubPart(sqmPath.getNavigablePath().getLocalName(), container);
    }
    // Plural path parts are not joined and thus also have no table group
    if (sqmPath instanceof AbstractSqmSpecificPluralPartPath<?>) {
        final TableGroup lhsTableGroup = tableGroupLocator.apply(sqmPath.getLhs().getLhs().getNavigablePath());
        final ModelPartContainer pluralPart = (ModelPartContainer) lhsTableGroup.getModelPart().findSubPart(sqmPath.getLhs().getReferencedPathSource().getPathName(), null);
        final CollectionPart collectionPart = (CollectionPart) pluralPart.findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
        // as that is the mapping type of the expression
        if (collectionPart instanceof EntityCollectionPart) {
            return ((EntityCollectionPart) collectionPart).getEntityMappingType();
        }
        return collectionPart;
    }
    if (sqmPath.getLhs() == null) {
        final EntityDomainType<?> entityDomainType = (EntityDomainType<?>) sqmPath.getReferencedPathSource();
        return domainModel.findEntityDescriptor(entityDomainType.getHibernateEntityName());
    }
    final TableGroup lhsTableGroup = tableGroupLocator.apply(sqmPath.getLhs().getNavigablePath());
    final ModelPartContainer modelPart;
    if (lhsTableGroup == null) {
        modelPart = (ModelPartContainer) resolveSqmPath(sqmPath.getLhs(), domainModel, tableGroupLocator);
    } else {
        modelPart = lhsTableGroup.getModelPart();
    }
    return modelPart.findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) AbstractSqmSpecificPluralPartPath(org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath) SqmTreatedPath(org.hibernate.query.sqm.tree.domain.SqmTreatedPath) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer)

Aggregations

CollectionPart (org.hibernate.metamodel.mapping.CollectionPart)14 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)9 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)9 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)8 EntityCollectionPart (org.hibernate.metamodel.mapping.internal.EntityCollectionPart)7 NavigablePath (org.hibernate.query.spi.NavigablePath)7 FetchTiming (org.hibernate.engine.FetchTiming)6 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)6 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)6 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)6 EmbeddableValuedModelPart (org.hibernate.metamodel.mapping.EmbeddableValuedModelPart)5 ModelPart (org.hibernate.metamodel.mapping.ModelPart)5 EmbeddedCollectionPart (org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart)5 FromClauseAccess (org.hibernate.sql.ast.spi.FromClauseAccess)5 CorrelatedPluralTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup)5 QueryPartTableGroup (org.hibernate.sql.ast.tree.from.QueryPartTableGroup)5 VirtualTableGroup (org.hibernate.sql.ast.tree.from.VirtualTableGroup)5 ArrayList (java.util.ArrayList)4 EntityAssociationMapping (org.hibernate.metamodel.mapping.EntityAssociationMapping)4 EntityPersister (org.hibernate.persister.entity.EntityPersister)4