diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java index 5dd757cfd304..d12027706a52 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java @@ -158,18 +158,18 @@ private EntityFetch buildEntityFetch( final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) resolveCompositeQuerySpace( loadPlanBuildingContext ); - final Join join = leftHandSide.addEntityJoin( - attributeDefinition, - fetchedPersister, - loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(), - attributeDefinition.isNullable() - ); final EntityFetch fetch; if ( targetEntityReference == null ) { + final Join join = leftHandSide.addEntityJoin( + attributeDefinition, + fetchedPersister, + loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(), + attributeDefinition.isNullable() + ); fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join ); } else { - fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, join, targetEntityReference ); + fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, targetEntityReference ); } addFetch( fetch ); return fetch; diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java index 8bbfe5068f11..6eabe81bd5fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java @@ -192,18 +192,18 @@ private EntityFetch buildEntityFetch( } final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) entityQuerySpace; - final Join join = leftHandSide.addEntityJoin( - attributeDefinition, - fetchedPersister, - loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(), - attributeDefinition.isNullable() - ); final EntityFetch fetch; if ( targetEntityReference == null ) { + final Join join = leftHandSide.addEntityJoin( + attributeDefinition, + fetchedPersister, + loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(), + attributeDefinition.isNullable() + ); fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join ); } else { - fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, join, targetEntityReference ); + fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, targetEntityReference ); } addFetch( fetch ); return fetch; diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/BidirectionalEntityFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/BidirectionalEntityFetchImpl.java index e76b4756f0d6..8f4822bf910c 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/BidirectionalEntityFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/BidirectionalEntityFetchImpl.java @@ -24,11 +24,17 @@ package org.hibernate.loader.plan2.build.internal.returns; import org.hibernate.engine.FetchStrategy; +import org.hibernate.loader.PropertyPath; import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource; import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch; +import org.hibernate.loader.plan2.spi.EntityFetch; +import org.hibernate.loader.plan2.spi.EntityIdentifierDescription; import org.hibernate.loader.plan2.spi.EntityReference; -import org.hibernate.loader.plan2.spi.Join; +import org.hibernate.loader.plan2.spi.Fetch; +import org.hibernate.loader.plan2.spi.FetchSource; +import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.walking.spi.AssociationAttributeDefinition; +import org.hibernate.type.EntityType; /** * Represents an entity fetch that is bi-directionally join fetched. @@ -39,20 +45,86 @@ * * @author Steve Ebersole */ -public class BidirectionalEntityFetchImpl extends EntityFetchImpl implements BidirectionalEntityFetch { +public class BidirectionalEntityFetchImpl implements BidirectionalEntityFetch, EntityFetch { + private final ExpandingFetchSource fetchSource; + private final AssociationAttributeDefinition fetchedAttribute; + private final FetchStrategy fetchStrategy; private final EntityReference targetEntityReference; + private final PropertyPath propertyPath; public BidirectionalEntityFetchImpl( ExpandingFetchSource fetchSource, AssociationAttributeDefinition fetchedAttribute, FetchStrategy fetchStrategy, - Join fetchedJoin, EntityReference targetEntityReference) { - super( fetchSource, fetchedAttribute, fetchStrategy, fetchedJoin ); + this.fetchSource = fetchSource; + this.fetchedAttribute = fetchedAttribute; + this.fetchStrategy = fetchStrategy; this.targetEntityReference = targetEntityReference; + this.propertyPath = fetchSource.getPropertyPath().append( fetchedAttribute.getName() ); } public EntityReference getTargetEntityReference() { return targetEntityReference; } + + @Override + public FetchSource getSource() { + return fetchSource; + } + + @Override + public PropertyPath getPropertyPath() { + return propertyPath; + } + + @Override + public FetchStrategy getFetchStrategy() { + return fetchStrategy; + } + + @Override + public EntityType getFetchedType() { + return (EntityType) fetchedAttribute.getType(); + } + + @Override + public boolean isNullable() { + return fetchedAttribute.isNullable(); + } + + @Override + public String getAdditionalJoinConditions() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String[] toSqlSelectFragments(String alias) { + return new String[0]; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String getQuerySpaceUid() { + return targetEntityReference.getQuerySpaceUid(); + } + + @Override + public Fetch[] getFetches() { + return FetchSource.NO_FETCHES; + } + + @Override + public EntityReference resolveEntityReference() { + return this; + } + + @Override + public EntityPersister getEntityPersister() { + return targetEntityReference.getEntityPersister(); + } + + @Override + public EntityIdentifierDescription getIdentifierDescription() { + return targetEntityReference.getIdentifierDescription(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ReturnGraphTreePrinter.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ReturnGraphTreePrinter.java index 8835988801d5..3789e913ae88 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ReturnGraphTreePrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ReturnGraphTreePrinter.java @@ -27,6 +27,7 @@ import java.io.PrintStream; import java.io.PrintWriter; +import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch; import org.hibernate.loader.plan2.spi.CollectionFetch; import org.hibernate.loader.plan2.spi.CollectionFetchableElement; import org.hibernate.loader.plan2.spi.CollectionFetchableIndex; @@ -152,6 +153,9 @@ private String extractDetails(CompositeFetch compositeFetch) { } private void writeEntityReferenceFetches(EntityReference entityReference, int depth, PrintWriter printWriter) { + if ( BidirectionalEntityFetch.class.isInstance( entityReference ) ) { + return; + } if ( entityReference.getIdentifierDescription().hasFetches() ) { printWriter.println( TreePrinterHelper.INSTANCE.generateNodePrefix( depth ) + "(entity id) " ); writeFetches( ( (FetchSource) entityReference.getIdentifierDescription() ).getFetches(), depth+1, printWriter );