Search in sources :

Example 1 with EntityQuerySpace

use of org.hibernate.loader.plan.spi.EntityQuerySpace in project hibernate-orm by hibernate.

the class LoadQueryJoinAndFetchProcessor method renderManyToManyJoin.

private void renderManyToManyJoin(Join join, JoinFragment joinFragment) {
    // for many-to-many we have 3 table aliases.  By way of example, consider a normal m-n: User<->Role
    // where User is the FetchOwner and Role (User.roles) is the Fetch.  We'd have:
    // 1) the owner's table : user - in terms of rendering the joins (not the fetch select fragments), the
    // lhs table alias is only needed to qualify the lhs join columns, but we already have the qualified
    // columns here (aliasedLhsColumnNames)
    // final String ownerTableAlias = ...;
    // 2) the m-n table : user_role
    // 3) the element table : role
    final EntityPersister entityPersister = ((EntityQuerySpace) join.getRightHandSide()).getEntityPersister();
    final String entityTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(join.getRightHandSide().getUid());
    if (StringHelper.isEmpty(entityTableAlias)) {
        throw new IllegalStateException("Collection element (many-to-many) table alias cannot be empty");
    }
    final String manyToManyFilter;
    if (JoinDefinedByMetadata.class.isInstance(join) && CollectionPropertyNames.COLLECTION_ELEMENTS.equals(((JoinDefinedByMetadata) join).getJoinedPropertyName())) {
        final CollectionQuerySpace leftHandSide = (CollectionQuerySpace) join.getLeftHandSide();
        final CollectionPersister persister = leftHandSide.getCollectionPersister();
        manyToManyFilter = persister.getManyToManyFilterFragment(entityTableAlias, buildingParameters.getQueryInfluencers().getEnabledFilters());
    } else {
        manyToManyFilter = null;
    }
    addJoins(join, joinFragment, (Joinable) entityPersister, manyToManyFilter);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) EntityQuerySpace(org.hibernate.loader.plan.spi.EntityQuerySpace) CollectionQuerySpace(org.hibernate.loader.plan.spi.CollectionQuerySpace)

Example 2 with EntityQuerySpace

use of org.hibernate.loader.plan.spi.EntityQuerySpace in project hibernate-orm by hibernate.

the class LoadQueryJoinAndFetchProcessor method renderEntityJoin.

private void renderEntityJoin(Join join, JoinFragment joinFragment) {
    final EntityQuerySpace rightHandSide = (EntityQuerySpace) join.getRightHandSide();
    // see if there is already aliases registered for this entity query space (collection joins)
    EntityReferenceAliases aliases = aliasResolutionContext.resolveEntityReferenceAliases(rightHandSide.getUid());
    if (aliases == null) {
        aliasResolutionContext.generateEntityReferenceAliases(rightHandSide.getUid(), rightHandSide.getEntityPersister());
    }
    final Joinable joinable = (Joinable) rightHandSide.getEntityPersister();
    addJoins(join, joinFragment, joinable, null);
}
Also used : EntityReferenceAliases(org.hibernate.loader.plan.exec.spi.EntityReferenceAliases) Joinable(org.hibernate.persister.entity.Joinable) EntityQuerySpace(org.hibernate.loader.plan.spi.EntityQuerySpace)

Aggregations

EntityQuerySpace (org.hibernate.loader.plan.spi.EntityQuerySpace)2 EntityReferenceAliases (org.hibernate.loader.plan.exec.spi.EntityReferenceAliases)1 CollectionQuerySpace (org.hibernate.loader.plan.spi.CollectionQuerySpace)1 JoinDefinedByMetadata (org.hibernate.loader.plan.spi.JoinDefinedByMetadata)1 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 Joinable (org.hibernate.persister.entity.Joinable)1