HHH-16210 Avoid join fetching multiple bag-type collections
This commit is contained in:
parent
8700f6f93b
commit
615267f61d
|
@ -29,6 +29,7 @@ import org.hibernate.graph.GraphSemantic;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.loader.ast.spi.Loadable;
|
import org.hibernate.loader.ast.spi.Loadable;
|
||||||
import org.hibernate.loader.ast.spi.Loader;
|
import org.hibernate.loader.ast.spi.Loader;
|
||||||
|
import org.hibernate.metamodel.CollectionClassification;
|
||||||
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
||||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||||
|
@ -793,7 +794,8 @@ public class LoaderSelectBuilder {
|
||||||
final String bagRole;
|
final String bagRole;
|
||||||
if ( isFetchablePluralAttributeMapping
|
if ( isFetchablePluralAttributeMapping
|
||||||
&& ( (PluralAttributeMapping) fetchable ).getMappedType()
|
&& ( (PluralAttributeMapping) fetchable ).getMappedType()
|
||||||
.getCollectionSemantics() instanceof BagSemantics ) {
|
.getCollectionSemantics()
|
||||||
|
.getCollectionClassification() == CollectionClassification.BAG ) {
|
||||||
bagRole = fetchable.getNavigableRole().getNavigableName();
|
bagRole = fetchable.getNavigableRole().getNavigableName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -801,7 +803,7 @@ public class LoaderSelectBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( joined && previousBagRole != null && bagRole != null ) {
|
if ( joined && previousBagRole != null && bagRole != null ) {
|
||||||
// Avoid join fetching multiple bags
|
// Avoid join fetching multiple bags to prevent result multiplication
|
||||||
joined = false;
|
joined = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -467,26 +467,21 @@ public class PluralAttributeMappingImpl
|
||||||
private Fetch createSelectEagerCollectionFetch(
|
private Fetch createSelectEagerCollectionFetch(
|
||||||
FetchParent fetchParent,
|
FetchParent fetchParent,
|
||||||
NavigablePath fetchablePath,
|
NavigablePath fetchablePath,
|
||||||
DomainResultCreationState creationState, SqlAstCreationState sqlAstCreationState) {
|
DomainResultCreationState creationState,
|
||||||
|
SqlAstCreationState sqlAstCreationState) {
|
||||||
|
final DomainResult<?> collectionKeyDomainResult;
|
||||||
if ( referencedPropertyName != null ) {
|
if ( referencedPropertyName != null ) {
|
||||||
resolveCollectionTableGroup(
|
collectionKeyDomainResult = getKeyDescriptor().createTargetDomainResult(
|
||||||
fetchParent,
|
|
||||||
fetchablePath,
|
|
||||||
creationState,
|
|
||||||
sqlAstCreationState
|
|
||||||
);
|
|
||||||
|
|
||||||
final DomainResult<?> collectionKeyDomainResult = getKeyDescriptor().createTargetDomainResult(
|
|
||||||
fetchablePath,
|
fetchablePath,
|
||||||
sqlAstCreationState.getFromClauseAccess().getTableGroup( fetchParent.getNavigablePath() ),
|
sqlAstCreationState.getFromClauseAccess().getTableGroup( fetchParent.getNavigablePath() ),
|
||||||
fetchParent,
|
fetchParent,
|
||||||
creationState
|
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(
|
private TableGroup resolveCollectionTableGroup(
|
||||||
|
|
Loading…
Reference in New Issue