Skip to content

Commit 6f8fddd

Browse files
gbadnersebersole
authored andcommitted
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
1 parent 0481eb8 commit 6f8fddd

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCollectionReference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ private CollectionFetchableElement buildElementGraph(
9595
final Type type = persister.getElementType();
9696
if ( type.isAssociationType() ) {
9797
if ( type.isEntityType() ) {
98-
final EntityPersister indexPersister = persister.getFactory().getEntityPersister(
98+
final EntityPersister elementPersister = persister.getFactory().getEntityPersister(
9999
( (EntityType) type ).getAssociatedEntityName()
100100
);
101101

102-
final Join join = collectionQuerySpace.addElementEntityJoin( indexPersister, loadPlanBuildingContext );
102+
final Join join = collectionQuerySpace.addElementEntityJoin( elementPersister, loadPlanBuildingContext );
103103
return new CollectionFetchableElementEntityGraph( this, join );
104104
}
105105
}

hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityFetchImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ public String[] toSqlSelectFragments(String alias) {
8989

9090
@Override
9191
public void validateFetchPlan(FetchStrategy fetchStrategy, AttributeDefinition attributeDefinition) {
92-
if ( attributeDefinition.getType().isCollectionType() ) {
93-
throw new WalkingException(
94-
"Encountered collection attribute in identifier fetches: " + attributeDefinition.getSource() +
95-
"." + attributeDefinition.getName()
96-
);
97-
}
9892
// todo : allow bi-directional key-many-to-one fetches?
9993
// those do cause problems in Loader; question is whether those are indicative of that situation or
10094
// of Loaders ability to handle it.

hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CollectionQuerySpaceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.hibernate.loader.plan2.spi.CollectionQuerySpace;
3030
import org.hibernate.loader.plan2.spi.Join;
3131
import org.hibernate.persister.collection.CollectionPersister;
32+
import org.hibernate.persister.collection.QueryableCollection;
3233
import org.hibernate.persister.entity.EntityPersister;
3334
import org.hibernate.persister.entity.PropertyMapping;
3435
import org.hibernate.persister.entity.Queryable;

hibernate-core/src/main/java/org/hibernate/loader/plan2/exec/internal/LoadQueryJoinAndFetchProcessor.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ private void renderJoin(Join join, JoinFragment joinFragment) {
125125
handleCompositeJoin( join, joinFragment );
126126
}
127127
else if ( EntityQuerySpace.class.isInstance( join.getRightHandSide() ) ) {
128-
renderEntityJoin( join, joinFragment );
128+
// do not render the entity join for a one-to-many association, since the collection join
129+
// already joins to the associated entity table (see doc in renderCollectionJoin()).
130+
if ( join.getLeftHandSide().getDisposition() != QuerySpace.Disposition.COLLECTION ||
131+
! CollectionQuerySpace.class.cast( join.getLeftHandSide() ).getCollectionPersister().isOneToMany() ) {
132+
renderEntityJoin( join, joinFragment );
133+
}
129134
}
130135
else if ( CollectionQuerySpace.class.isInstance( join.getRightHandSide() ) ) {
131136
renderCollectionJoin( join, joinFragment );
@@ -249,14 +254,14 @@ private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
249254
rightHandSide.getCollectionPersister()
250255
);
251256

252-
// if the collection being joined is a one-to-many there is actually nothing to render here - there will
253-
// be a follow-on join (rhs will have a join) for the associated entity.
257+
// The SQL join to the "collection table" needs to be rendered.
254258
//
255-
// otherwise the SQL join to the "collection table" needs to be rendered. In the case of a basic collection,
256-
// that's the only join needed. For many-to-many, we need to render the "collection table join" here (as
257-
// already stated), but joining to the entity element table is handled by a follow-on join for the associated
258-
// entity as discussed with regard to one-to-many
259+
// In the case of a basic collection, that's the only join needed.
259260
//
261+
// For one-to-many/many-to-many, we need to render the "collection table join"
262+
// here (as already stated). There will be a follow-on join (rhs will have a join) for the associated entity.
263+
// For many-to-many, the follow-on join will join to the associated entity element table. For one-to-many,
264+
// the collection table is the associated entity table, so the follow-on join will not be rendered..
260265

261266
if ( rightHandSide.getCollectionPersister().isOneToMany()
262267
|| rightHandSide.getCollectionPersister().isManyToMany() ) {
@@ -298,11 +303,6 @@ private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
298303
);
299304
}
300305

301-
if ( rightHandSide.getCollectionPersister().isOneToMany() ) {
302-
// as stated, nothing to do...
303-
return;
304-
}
305-
306306
renderSqlJoinToCollectionTable(
307307
aliases,
308308
rightHandSide,

0 commit comments

Comments
 (0)