File tree 2 files changed +21
-1
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core/query
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 37
37
* @author Mark Paluch
38
38
* @author Owen Q
39
39
* @author Kirill Egorov
40
+ * @author GaEun Kim
40
41
*/
41
42
public class Field {
42
43
@@ -286,7 +287,7 @@ public boolean equals(@Nullable Object o) {
286
287
@ Override
287
288
public int hashCode () {
288
289
289
- int result = ObjectUtils .nullSafeHashCode (criteria );
290
+ int result = ObjectUtils .nullSafeHashCode (criteria . toString () );
290
291
result = 31 * result + ObjectUtils .nullSafeHashCode (slices );
291
292
result = 31 * result + ObjectUtils .nullSafeHashCode (elemMatches );
292
293
result = 31 * result + ObjectUtils .nullSafeHashCode (positionKey );
Original file line number Diff line number Diff line change 28
28
* @author Owen Q
29
29
* @author Mark Paluch
30
30
* @author Kirill Egorov
31
+ * @author GaEun Kim
31
32
*/
32
33
class FieldUnitTests {
33
34
@@ -85,4 +86,22 @@ void overriddenExclusionMethodsCreateEqualFields() {
85
86
86
87
assertThat (left ).isEqualTo (right );
87
88
}
89
+
90
+ @ Test
91
+ void assertDifferentHashCodesForExcludeAndIncludeQueries () {
92
+
93
+ Query queryWithExclude = new Query ();
94
+ queryWithExclude .fields ().exclude ("key1" );
95
+ queryWithExclude .fields ().exclude ("key2" );
96
+ queryWithExclude .fields ().exclude ("field1" );
97
+ queryWithExclude .fields ().exclude ("field2" );
98
+
99
+ Query queryWithInclude = new Query ();
100
+ queryWithInclude .fields ().include ("key1" );
101
+ queryWithInclude .fields ().include ("key2" );
102
+ queryWithInclude .fields ().include ("field1" );
103
+ queryWithInclude .fields ().include ("field2" );
104
+
105
+ assertThat (queryWithExclude .hashCode ()).isNotEqualTo (queryWithInclude .hashCode ());
106
+ }
88
107
}
You can’t perform that action at this time.
0 commit comments