当前位置: 首页 > 知识库问答 >
问题:

找不到Hazelcast谓词/SQL查询类

白志勇
2023-03-14
Oct 01, 2021 10:57:14 AM com.hazelcast.map.impl.query.QueryPartitionOperation
SEVERE: [192.168.99.1]:5701 [nifi] [4.2.1] java.lang.ClassNotFoundException: com.mypackage.TestValue
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.mypackage.TestValue
        at com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:90)
        at com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:79)
        at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:44)
        at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:208)
        at com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:98)
        at com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:185)
        at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:108)
        at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:62)
        at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:145)
        at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:62)
        at com.hazelcast.query.impl.predicates.AndPredicate.apply(AndPredicate.java:136)
        at com.hazelcast.map.impl.query.PartitionScanRunner$1.accept(PartitionScanRunner.java:104)
        at com.hazelcast.map.impl.query.PartitionScanRunner$1.accept(PartitionScanRunner.java:89)
        at com.hazelcast.map.impl.recordstore.DefaultRecordStore.forEach(DefaultRecordStore.java:278)
        at com.hazelcast.map.impl.recordstore.DefaultRecordStore.forEach(DefaultRecordStore.java:261)
        at com.hazelcast.map.impl.recordstore.DefaultRecordStore.forEachAfterLoad(DefaultRecordStore.java:291)
        at com.hazelcast.map.impl.query.PartitionScanRunner.run(PartitionScanRunner.java:89)
        at com.hazelcast.map.impl.query.CallerRunsPartitionScanExecutor.execute(CallerRunsPartitionScanExecutor.java:43)
        at com.hazelcast.map.impl.query.QueryRunner.runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(QueryRunner.java:236)
        at com.hazelcast.map.impl.query.QueryPartitionOperation.runInternal(QueryPartitionOperation.java:46)
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:115)
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:189)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:272)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:248)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:213)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:175)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:139)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123)
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
Caused by: java.lang.ClassNotFoundException: com.mypackage.TestValue
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at com.hazelcast.internal.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:289)
        at com.hazelcast.internal.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:249)
        at com.hazelcast.internal.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:910)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1984)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1848)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2158)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1665)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:501)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:459)
        at com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:86)
        ... 28 more
Collection<HazelcastInstance> instances = HazelcastClient.getAllHazelcastClients();
Optional<HazelcastInstance> instance = instances.stream().findAny();
if (!instance.isPresent()) return;

IMap<String, TestValue> cacheMap = instance.get().getMap("test");
cacheMap.put("1", new TestValue(1, 1L));
cacheMap.put("2", new TestValue(2, 2L));
cacheMap.put("5", new TestValue(5, 5L));
cacheMap.put("9", new TestValue(9, 9L));

TestValue tv = cacheMap.get("1"); // works    
Collection<TestValue> values = cacheMap.values(); // works

Predicate<String, TestValue> gt = Predicates.greaterThan("testInt", 3);
Predicate<String, TestValue> lt = Predicates.lessThan("testInt", 7);
Predicate<String, TestValue> predicate = Predicates.and(gt, lt);
Collection<TestValue> testValues = cacheMap.values(predicate); // fails

SqlRow row = instance.get().getSql().execute("SELECT this FROM test WHERE testInt = 1").iterator().next(); // fails with whatever query I try

TestValue类是简单的pojo

public class TestValue implements Serializable {
    private static final long serialVersionUID = 333333L;
    private Integer testInt;
    private Long testLong;

    public TestValue(Integer testInt, Long testLong) {
        this.testInt = testInt;
        this.testLong = testLong;
    }

    public TestValue() {
    }

    public Integer getTestInt() {
        return testInt;
    }

    public Long getTestLong() {
        return testLong;
    }

    public void setTestInt(Integer testInt) {
        this.testInt = testInt;
    }

    public void setTestLong(Long testLong) {
        this.testLong = testLong;
    }
}

这只是本地env,所有的东西都在我的机器上运行,单个Hazelcast实例。我的代码与官方文档中的示例相匹配。

Hazelcast版本:4.2.1

共有1个答案

萧明贤
2023-03-14

代码如下所示:

Collection<HazelcastInstance> instances = HazelcastClient.getAllHazelcastClients();
Optional<HazelcastInstance> instance = instances.stream().findAny();

这意味着Hazelcast实例是一个客户机。因此,必须有一个Hazelcast节点作为单独的进程运行。

问题是您的类在客户端是已知的,而不是在服务器端。由于查询是在服务器端运行的,因此您需要在启动类时将类放在服务器类路径上,或者用JSON序列化类,以便可以以一种不可知的方式查询它。

 类似资料:
  • 我正在尝试构建一个方法,删除具有非空属性的条目,但我一直在谓词中失败,我不知道如何正确实现谓词,因为hazelcast没有将“Not NULL”或“IS NULL”作为where子句任何想法如何在映射中找到我需要搜索以删除它们的值? 方法 主类响应SerializablePlus

  • 我正在使用一个应用程序,我们SQL服务器作为数据库。需要在SQL服务器上添加HazelCast缓存层。 这是一个遗留系统,其工作方式类似于SQL服务,其中针对SQLServer DB执行的SQL查询存储在配置表中。 例如,有一个通过查询返回数据的UI: 这是动态获取、检索并针对数据库执行的。有许多这样的视图是通过动态查询呈现的。在HazelCast中,这些SQL语法中的一些不仅适用。 是否有任何数

  • 我有一个淡褐色IMAP看起来像 在val1,val2上建立索引我正在尝试获取say

  • 谁能告诉我如何用Hazelcast谓词“in”子句吗。我想使用以下内容, 我想将值作为值的ArrayList传递。但是它抛出错误,因为它期望实现可比的对象。对此有任何解决方法吗?

  • 环境是Java、Spring-boot、Hibernat、QueryDSL、MySQL。 我有表结构 艾碧索 更新 为了澄清起见,支持UI视图的DTO包含“casename”属性。它是在将域对象转换为DTO时在服务层创建的:

  • 在hazelcast IMap中查找谓词结果大小的最佳方法是什么? MapProxyImpl中不支持直接大小。java和size()将根据返回的集合进行计算,在这种情况下,这是不需要的。 你有什么建议吗? 谢谢