Search code examples
hazelcast

Entries with differing number of fields


I want to cache data that will have different, changing fields.

I am adding an entry to the IMap where the value is a Map but I when I try to use Predicates to search on the values in the Map I get an error in the ReflectionHelper.

(I am using the Spring JDBC template to load the data from a DB table where one of the columns is a BLOB and then I put the Map into the cache)

Is there a pattern/approach to use where I can cache a map of values and then search on the values within the Map? Perhaps I should use a MultiMap where the values are tuples with name/value pairs?

Caused by: java.lang.IllegalArgumentException: There is no suitable accessor for '['CURRENCY']' on class 'class org.springframework.util.LinkedCaseInsensitiveMap'
at com.hazelcast.query.impl.getters.ReflectionHelper.createGetter(ReflectionHelper.java:192)
at com.hazelcast.query.impl.getters.ReflectionHelper.extractValue(ReflectionHelper.java:209)

Solution

  • Please check this example: https://github.com/hazelcast/hazelcast-code-samples/tree/master/distributed-map/custom-attributes/src/main/java/com/test/car/attribute

    What you need to do is to create a generic value extractor that can extract values from a given object, in your case map, and use it while querying.

    In this sample, Car class has a map property but same also works without a wrapping class.