Hi guys! Thanks, seems that it's all I need
With best regards Alisher Alimov [email protected] > On 10 Jan 2017, at 23:53, Denis Magda <[email protected]> wrote: > > Hi Alisher, > > You need to fields identity resolver if want to specify a set of fields to be > used for hashCode and equals. > http://apacheignite.gridgain.org/docs/binary-marshaller#section-binary-field-identity-resolver > > <http://apacheignite.gridgain.org/docs/binary-marshaller#section-binary-field-identity-resolver> > > — > Denis > >> On Jan 10, 2017, at 5:30 AM, Alisher Alimov <[email protected] >> <mailto:[email protected]>> wrote: >> >> Hello! >> >> I have a little problem when try to use object as key with BinaryMarshaller. >> Bug occurred only with BinaryMarshaller, on JdkMarshaller all is working >> fine as expected. >> >> Here is example: >> >> UserObject class used as key that override hashCode and equals methods but >> seems that BinaryMarshaller using all fields from key object for building >> hashCode >> >> private static class UserObject implements Serializable { >> private final Integer id; >> private final Integer notIdField; >> >> UserObject(Integer id, Integer notIdField) { >> this.id = id; >> this.notIdField = notIdField; >> } >> >> public Integer getId() { >> return id; >> } >> >> public Integer getNotIdField() { >> return notIdField; >> } >> >> @Override >> public int hashCode() { >> return Objects.hash(id); >> } >> >> @Override >> public boolean equals(Object obj) { >> if (obj instanceof UserObject) { >> return Objects.equals(((UserObject) obj).getId(), getId()); >> } >> >> return false; >> } >> } >> >> >> public void testObjectKey() throws Exception { >> IgniteCache<UserObject, Integer> cache = ignite.getOrCreateCache("test"); >> >> >> for (int i = 0; i < 10; i++) { >> cache.put(new UserObject(0, i), i); >> >> Assert.assertEquals(1, cache.size(CachePeekMode.PRIMARY)); >> } >> >> } >> >> Is it expected behaviour or bug? >> >> With best regards >> Alisher Alimov >> [email protected] <mailto:[email protected]> >> >> >> >> >
