Skip to content

Commit 16b7592

Browse files
committed
HHH-17002, HHH-18820, HHH-19391, HHH-18514 add comments explaining an important point
1 parent db5357d commit 16b7592

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,18 @@ public <X> SqmEntityJoin<R, X> join(Class<X> targetEntityClass, SqmJoinType join
156156

157157
@Override
158158
public boolean equals(Object object) {
159-
return object instanceof AbstractSqmJoin<?, ?> that
160-
&& super.equals( object )
161-
&& this.joinType == that.joinType; // unnecessary, but harmless
162-
// && Objects.equals( onClausePredicate, that.onClausePredicate ); // including this causes problems
159+
// Note that this implementation of equals() is only used for
160+
// and is only correct when comparing use of AbstractSqmJoin
161+
// within path expressions. See SqmFromClause.equalsJoins().
162+
return object instanceof AbstractSqmJoin
163+
&& super.equals( object );
164+
// We do not need to include these in the comparison because
165+
// this is taken care of in SqmFromClause.equalsJoins(), which
166+
// exists because including the onClausePredicate would result
167+
// in a circularity when comparing AbstractSqmJoin in path
168+
// expressions.
169+
// && this.joinType == that.joinType
170+
// && Objects.equals( this.onClausePredicate, that.onClausePredicate );
163171
}
164172

165173
@Override

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFromClause.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public static void appendTreatJoins(SqmFrom<?, ?> sqmFrom, StringBuilder sb, Sqm
192192
public boolean equals(Object object) {
193193
return object instanceof SqmFromClause that
194194
&& this.getNumberOfRoots() == that.getNumberOfRoots()
195+
// calling equals() here leads to circularity,
196+
// and so we need to flatten out the comparison
195197
&& equalRoots( this.getRoots(), that.getRoots() );
196198
}
197199

0 commit comments

Comments
 (0)