HHH-16210 Avoid join fetching multiple bag-type collections
This commit is contained in:
parent
7fd8d0de12
commit
e08b59a063
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue