Ignite doesn’t use your equals or hashCode implementation. Data is stored as a BinaryObject, and it’s that that is compared for equality.
> On 22 Mar 2023, at 12:14, Humphrey Lopez <hmmlo...@gmail.com> wrote: > > They are in the example only checking the first field when overriding the > equals. And hashCode always returns 1. > > Op wo 22 mrt 2023 om 13:06 schreef Prigoreanu, Alexandru > <prigoreanu.alexan...@anteash.com <mailto:prigoreanu.alexan...@anteash.com>>: >> hashCode and equals should depend on the same fields. >> >> On Wed, Mar 22, 2023 at 8:02 AM Humphrey Lopez <hmmlo...@gmail.com >> <mailto:hmmlo...@gmail.com>> wrote: >>> Hello, when having a key which equals another key, when trying to retrieve >>> from cache it does not return the expected value. Is this a bug? >>> >>> I have a reproducible below in kotlin but in java we get the same result >>> (test with Ignite 2.10 and 2.14) and java 11 and 19. >>> >>> import org.apache.ignite.Ignition >>> import org.apache.ignite.configuration.CacheConfiguration >>> import org.assertj.core.api.SoftAssertions >>> import org.junit.jupiter.api.Test >>> >>> class MyTest { >>> >>> private val key1 = MyKey("ABC", "DEF") >>> private val key2 = MyKey("ABC", "xxx") >>> >>> @Test >>> fun testEquals() { >>> SoftAssertions.assertSoftly { >>> it.assertThat(key1).isEqualTo(key2) >>> it.assertThat(key1 == key2).isTrue >>> } >>> } >>> >>> @Test >>> fun testWithMap() { >>> val map = mapOf(Pair(key1, "key1")) >>> >>> SoftAssertions.assertSoftly { >>> it.assertThat(map.containsKey(key1)).isTrue >>> it.assertThat(map.containsKey(key2)).isTrue >>> } >>> >>> } >>> >>> @Test >>> fun testWithIgnite() { >>> val ignite = Ignition.start(); >>> val cache = ignite.createCache(CacheConfiguration<MyKey, >>> String>("mycache")) >>> >>> cache.put(key1, "key1") >>> SoftAssertions.assertSoftly { >>> it.assertThat(cache.containsKey(key1)).isTrue >>> it.assertThat(cache.containsKey(key2)).isTrue >>> } >>> } >>> >>> private data class MyKey(val id: String, val type: String) { >>> override fun equals(other: Any?): Boolean { >>> if (other is MyKey) >>> return id == other.id >>> return false >>> } >>> >>> override fun hashCode(): Int { >>> return 1 >>> } >>> } >>> }