diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java index 1e28f45fc0..b1d16b9c00 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java @@ -29,6 +29,7 @@ import org.hibernate.graph.GraphSemantic; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.loader.ast.spi.Loadable; import org.hibernate.loader.ast.spi.Loader; +import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.mapping.BasicValuedModelPart; import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.mapping.EntityIdentifierMapping; @@ -793,7 +794,8 @@ public class LoaderSelectBuilder { final String bagRole; if ( isFetchablePluralAttributeMapping && ( (PluralAttributeMapping) fetchable ).getMappedType() - .getCollectionSemantics() instanceof BagSemantics ) { + .getCollectionSemantics() + .getCollectionClassification() == CollectionClassification.BAG ) { bagRole = fetchable.getNavigableRole().getNavigableName(); } else { @@ -801,7 +803,7 @@ public class LoaderSelectBuilder { } if ( joined && previousBagRole != null && bagRole != null ) { - // Avoid join fetching multiple bags + // Avoid join fetching multiple bags to prevent result multiplication joined = false; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java index 50428e66f7..8fe858e22d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java @@ -467,26 +467,21 @@ public class PluralAttributeMappingImpl private Fetch createSelectEagerCollectionFetch( FetchParent fetchParent, NavigablePath fetchablePath, - DomainResultCreationState creationState, SqlAstCreationState sqlAstCreationState) { + DomainResultCreationState creationState, + SqlAstCreationState sqlAstCreationState) { + final DomainResult collectionKeyDomainResult; if ( referencedPropertyName != null ) { - resolveCollectionTableGroup( - fetchParent, - fetchablePath, - creationState, - sqlAstCreationState - ); - - final DomainResult collectionKeyDomainResult = getKeyDescriptor().createTargetDomainResult( + collectionKeyDomainResult = getKeyDescriptor().createTargetDomainResult( fetchablePath, sqlAstCreationState.getFromClauseAccess().getTableGroup( fetchParent.getNavigablePath() ), fetchParent, creationState ); - - return new SelectEagerCollectionFetch( fetchablePath, this, collectionKeyDomainResult, fetchParent ); - } - return new SelectEagerCollectionFetch( fetchablePath, this, null, fetchParent ); + else { + collectionKeyDomainResult = null; + } + return new SelectEagerCollectionFetch( fetchablePath, this, collectionKeyDomainResult, fetchParent ); } private TableGroup resolveCollectionTableGroup(