HHH-17662 Equals for ArrayJdbcType
JdbcTypes are put into a map and deduplicated there. Without an equals the ArrayJdbcType leaks because each resolution is created new.
This commit is contained in:
parent
439fac712b
commit
5d348fc723
|
@ -203,4 +203,22 @@ public class ArrayJdbcType implements JdbcType {
|
|||
public String toString() {
|
||||
return "ArrayTypeDescriptor";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check equality. Needed so that ArrayJdbcType in collections correctly match each other.
|
||||
*
|
||||
* @param o other object
|
||||
* @return true if the two array types share the same element type
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o != null &&
|
||||
getClass() == o.getClass() &&
|
||||
getElementJdbcType().equals( ((ArrayJdbcType) o).getElementJdbcType() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getJdbcTypeCode() + getElementJdbcType().hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.hibernate.orm.test.type.descriptor.jdbc;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.type.descriptor.jdbc.ArrayJdbcType;
|
||||
import org.hibernate.type.descriptor.jdbc.BigIntJdbcType;
|
||||
import org.hibernate.type.descriptor.jdbc.IntegerJdbcType;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class ArrayJdbcTypeTest {
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-17662")
|
||||
public void testEquality() {
|
||||
Map<JdbcType, String> typeMap = new HashMap<>();
|
||||
JdbcType bigInt = new BigIntJdbcType();
|
||||
typeMap.put(new ArrayJdbcType(bigInt), "bees");
|
||||
typeMap.put(new ArrayJdbcType(bigInt), "bees");
|
||||
typeMap.put(new ArrayJdbcType(bigInt), "bees");
|
||||
typeMap.put(new ArrayJdbcType(new IntegerJdbcType()), "waffles");
|
||||
assertThat("A map of arrays only contains non duplicate entries", typeMap.size() == 2);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue