首页 > 解决方案 > HazelcastException:不能将 EqualPredicate 谓词与数组或集合属性一起使用

问题描述

我将用户及其位置存储在 hazelcast 中。当我对面临异常的位置进行查询时。

我正在使用 hazelcast 3.12.1版本

我遵循了 hazelcast 的参考手册 https://docs.hazelcast.org/docs/latest/manual/html-single/#querying-in-collections-and-arrays

Predicate pagingPredicate = new PagingPredicate<String, User>(
            new SqlPredicate("userActive  AND ( locations=null OR  ( locations[any].country='India' AND locations[any].state='Telangana' AND locations[any].city='Hyderabad' ) )"), PRICE_COMPARATOR, 2);
        return usersMap.values(pagingPredicate)

和我的 PriceComparator.java

public class PriceComparator implements Comparator<Entry<String, User>>,
    Serializable {

    private static final long serialVersionUID = -198157764684077461L;

    @Override
    public int compare(Entry<String, User> o1, Entry<String, User> o2) {
        return Double.compare(o2.getValue().getSalary().doubleValue(),
            o1.getValue().getSalary().doubleValue());
    }
}

我希望缓存应该返回一些值,但我却面临异常

java.lang.IllegalArgumentException: Cannot use EqualPredicate predicate with an array or a collection attribute

谁可以帮我这个事。

标签: spring-boothazelcasthazelcast-imap

解决方案


终于问题解决了。由于条件,这是一个问题locations=null。当我用它替换这个条件时,locations.size=0它工作得很好。

我无法弄清楚为什么null检查集合会引发异常?

如果有人有答案请告诉我


推荐阅读