File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
main/java/org/hibernate/type/descriptor/jdbc
test/java/org/hibernate/orm/test/type/descriptor/jdbc Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -203,4 +203,22 @@ public String getFriendlyName() {
203203 public String toString () {
204204 return "ArrayTypeDescriptor" ;
205205 }
206+
207+ /**
208+ * Check equality. Needed so that ArrayJdbcType in collections correctly match each other.
209+ *
210+ * @param o other object
211+ * @return true if the two array types share the same element type
212+ */
213+ @ Override
214+ public boolean equals (Object o ) {
215+ return o != null &&
216+ getClass () == o .getClass () &&
217+ getElementJdbcType ().equals ( ((ArrayJdbcType ) o ).getElementJdbcType () );
218+ }
219+
220+ @ Override
221+ public int hashCode () {
222+ return getJdbcTypeCode () + getElementJdbcType ().hashCode ();
223+ }
206224}
Original file line number Diff line number Diff line change 1+ package org .hibernate .orm .test .type .descriptor .jdbc ;
2+
3+ import org .hibernate .testing .TestForIssue ;
4+ import org .hibernate .type .descriptor .jdbc .ArrayJdbcType ;
5+ import org .hibernate .type .descriptor .jdbc .BigIntJdbcType ;
6+ import org .hibernate .type .descriptor .jdbc .IntegerJdbcType ;
7+ import org .hibernate .type .descriptor .jdbc .JdbcType ;
8+ import org .junit .jupiter .api .Test ;
9+
10+ import java .util .HashMap ;
11+ import java .util .Map ;
12+
13+ import static org .hamcrest .MatcherAssert .assertThat ;
14+
15+ public class ArrayJdbcTypeTest {
16+ @ Test
17+ @ TestForIssue (jiraKey = "HHH-17662" )
18+ public void testEquality () {
19+ Map <JdbcType , String > typeMap = new HashMap <>();
20+ JdbcType bigInt = new BigIntJdbcType ();
21+ typeMap .put (new ArrayJdbcType (bigInt ), "bees" );
22+ typeMap .put (new ArrayJdbcType (bigInt ), "bees" );
23+ typeMap .put (new ArrayJdbcType (bigInt ), "bees" );
24+ typeMap .put (new ArrayJdbcType (new IntegerJdbcType ()), "waffles" );
25+ assertThat ("A map of arrays only contains non duplicate entries" , typeMap .size () == 2 );
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments