Skip to content

Commit 8c12f2a

Browse files
committed
HHH-19753 Correct equals/hashCode for SqmFunction and subtypes
1 parent 56e5a13 commit 8c12f2a

File tree

5 files changed

+76
-15
lines changed

5 files changed

+76
-15
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmAggregateFunction.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.ArrayList;
88
import java.util.List;
9+
import java.util.Objects;
910

1011
import org.hibernate.metamodel.model.domain.ReturnableType;
1112
import org.hibernate.query.sqm.NodeBuilder;
@@ -123,4 +124,24 @@ public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
123124
hql.append( ')' );
124125
}
125126
}
127+
128+
@Override
129+
public boolean equals(Object o) {
130+
if ( o == null || getClass() != o.getClass() ) {
131+
return false;
132+
}
133+
if ( !super.equals( o ) ) {
134+
return false;
135+
}
136+
137+
SelfRenderingSqmAggregateFunction<?> that = (SelfRenderingSqmAggregateFunction<?>) o;
138+
return Objects.equals( filter, that.filter );
139+
}
140+
141+
@Override
142+
public int hashCode() {
143+
int result = super.hashCode();
144+
result = 31 * result + Objects.hashCode( filter );
145+
return result;
146+
}
126147
}

hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.ArrayList;
88
import java.util.List;
9-
import java.util.Objects;
109
import java.util.function.Supplier;
1110

1211
import org.hibernate.metamodel.mapping.BasicValuedMapping;
@@ -255,16 +254,4 @@ public MappingModelExpressible<?> get() {
255254
return argumentTypeResolver.resolveFunctionArgumentType( function.getArguments(), argumentIndex, converter );
256255
}
257256
}
258-
259-
@Override
260-
// TODO: override on all subtypes
261-
public boolean equals(Object other) {
262-
return other instanceof SelfRenderingSqmAggregateFunction<?> that
263-
&& Objects.equals( this.toHqlString(), that.toHqlString() );
264-
}
265-
266-
@Override
267-
public int hashCode() {
268-
return toHqlString().hashCode();
269-
}
270257
}

hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmOrderedSetAggregateFunction.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.Collections;
99
import java.util.List;
10+
import java.util.Objects;
1011

1112
import org.hibernate.metamodel.model.domain.ReturnableType;
1213
import org.hibernate.query.sqm.NodeBuilder;
@@ -173,4 +174,24 @@ public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
173174
hql.append( ')' );
174175
}
175176
}
177+
178+
@Override
179+
public boolean equals(Object o) {
180+
if ( o == null || getClass() != o.getClass() ) {
181+
return false;
182+
}
183+
if ( !super.equals( o ) ) {
184+
return false;
185+
}
186+
187+
SelfRenderingSqmOrderedSetAggregateFunction<?> that = (SelfRenderingSqmOrderedSetAggregateFunction<?>) o;
188+
return Objects.equals( withinGroup, that.withinGroup );
189+
}
190+
191+
@Override
192+
public int hashCode() {
193+
int result = super.hashCode();
194+
result = 31 * result + Objects.hashCode( withinGroup );
195+
return result;
196+
}
176197
}

hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmWindowFunction.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.ArrayList;
88
import java.util.List;
9+
import java.util.Objects;
910

1011
import org.hibernate.metamodel.model.domain.ReturnableType;
1112
import org.hibernate.query.sqm.NodeBuilder;
@@ -157,4 +158,28 @@ public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
157158
hql.append( ')' );
158159
}
159160
}
161+
162+
@Override
163+
public boolean equals(Object o) {
164+
if ( o == null || getClass() != o.getClass() ) {
165+
return false;
166+
}
167+
if ( !super.equals( o ) ) {
168+
return false;
169+
}
170+
171+
SelfRenderingSqmWindowFunction<?> that = (SelfRenderingSqmWindowFunction<?>) o;
172+
return Objects.equals( filter, that.filter )
173+
&& Objects.equals( respectNulls, that.respectNulls )
174+
&& Objects.equals( fromFirst, that.fromFirst );
175+
}
176+
177+
@Override
178+
public int hashCode() {
179+
int result = super.hashCode();
180+
result = 31 * result + Objects.hashCode( filter );
181+
result = 31 * result + Objects.hashCode( respectNulls );
182+
result = 31 * result + Objects.hashCode( fromFirst );
183+
return result;
184+
}
160185
}

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFunction.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,15 @@ public SqmPath<?> resolveIndexedAccess(
206206

207207
@Override
208208
public boolean equals(Object other) {
209-
return other instanceof SqmFunction<?> that
210-
&& Objects.equals( this.functionName, that.functionName )
209+
if ( this == other ) {
210+
return true;
211+
}
212+
if ( other == null || getClass() != other.getClass() ) {
213+
return false;
214+
}
215+
216+
final SqmFunction<?> that = (SqmFunction<?>) other;
217+
return Objects.equals( this.functionName, that.functionName )
211218
&& Objects.equals( this.arguments, that.arguments );
212219
}
213220

0 commit comments

Comments
 (0)