Okay transient is also not the way to go, cause we want to be able to
filter sometimes on that field, so it should be there in the cache. But
thanks for clarifying that the Equals and HashCode is not being used on
BinaryObjects.

Op wo 22 mrt 2023 om 14:51 schreef Humphrey Lopez <hmmlo...@gmail.com>:

> I see marking the field as Transient Ignite won't serialize it to
> BinaryObject, is that the way to go?
>
> Humphrey
>
> Op wo 22 mrt 2023 om 14:37 schreef Humphrey Lopez <hmmlo...@gmail.com>:
>
>> Thanks for clarifying that. Is there a way to mark a property/field to be
>> excluded when storing?
>>
>> Humphrey
>>
>> Op wo 22 mrt 2023 om 14:20 schreef Stephen Darlington <
>> stephen.darling...@gridgain.com>:
>>
>>> 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>:
>>>
>>>> hashCode and equals should depend on the same fields.
>>>>
>>>> On Wed, Mar 22, 2023 at 8:02 AM Humphrey Lopez <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
>>>>>         }
>>>>>     }
>>>>> }
>>>>>
>>>>>
>>>

Reply via email to