t seems you can use name, author pair as a key and price and other properties 
as a value like that:


class BooKey 
    String name;
    String author;
}

class BookValue {
    int price;
}

IgniteCache<BookKey, BookValue> cache = ignite.createCache(«books»);

cache.put(key, val);
cache.get(key);

> 21 июня 2022 г., в 18:09, Stephen Darlington 
> <stephen.darling...@gridgain.com> написал(а):
> 
> I don’t understand why can you can't use SQL. “select _val from Book where 
> bookName = ? And authorName = ?” would get the value from a partial key.
> 
>> On 21 Jun 2022, at 15:14, Saurabh Satardekar <satardekarsaur...@gmail.com 
>> <mailto:satardekarsaur...@gmail.com>> wrote:
>> 
>> Hi Stephen,
>> 
>> Thank you for replying.
>> 
>> In our use case we cannot use sql queries to get desired result. Is there 
>> any other way that we can use to plug custom implementation of equals and 
>> hashCode method for objects which are going to store in caches?
>> 
>> Thank you ,
>> Saurabh Satardekar.
>> 
>> 
>> 
>> On Fri, 17 Jun 2022, 9:42 pm Stephen Darlington, 
>> <stephen.darling...@gridgain.com <mailto:stephen.darling...@gridgain.com>> 
>> wrote:
>> If you enable SQL on your table, then you can run a query that filters on a 
>> subset of the properties. You can also add an index to make the lookup more 
>> quickly.
>> 
>>> On 17 Jun 2022, at 16:55, Saurabh Satardekar <satardekarsaur...@gmail.com 
>>> <mailto:satardekarsaur...@gmail.com>> wrote:
>>> 
>>> 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.
>> 
> 

Reply via email to