i face similar case,i implement key like below,and put jar contains contactKey class into ignite lib .then i can get result
public class ContactKey implements Externalizable { private Long id; @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ContactKey that = (ContactKey) o; return Objects.equal(id, that.id); } @Override public int hashCode() { return Objects.hashCode(id); } @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeLong(id); } @Override public void readExternal(ObjectInput in) throws IOException { this.id = in.readLong(); } Saurabh Satardekar <satardekarsaur...@gmail.com> 于2022年6月17日周五 23:57写道: > Respected Sir/Madam, > > We have following use case where we have Book class as follows : > > public class Book { > > private int price; > > private String bookName; > > private String authorName; > > public Book( String bookName, String authorName, int price ) { > > this.bookName = bookName; > > this.authorName = authorName; > > this.price = price; > > } > > @Override > > public boolean equals(Object o) { > > if( this == o ) return true; > > if( o == null || getClass() != o.getClass() ) return false; > > Book that = (Book) o; > > return bookName.equals(that.bookName) && > authorName.equals(that.authorName); > > } > > @Override > > public int hashCode() { > > return Objects.hash(bookName,authorName); > > } > > } > > For the above class we need to compare books by using book name and its > author name only. We don't want to include price while comparing books but > we can't even store that information anywhere else. > So if I have two objects as follows : > > Book book_1 = new Book("Book_1","ABC",100); > Book book_2 = new Book("Book_1","ABC",200); > > For above objects, if I use book_1 object as my cache key and put some > value against it into cache, I am not able to retrieve that value using my > another object book_2 as ignite is not honoring equals method provided on > Book class. > > We have tried implementing Externalizable interface and also by providing > custom implementation of BinaryIdentityResolver interface. Still we are not > getting desired output. > > > Note : This is a sample class which we have used to describe a problem, in > reality we are using other classes and we have a valid use case where we > don't want to use all attributes of the class while comparing them for > equality ( in equals and hashCode method ). > > > Thank you, > Saurabh Satardekar. >