Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

java - Hazelcast SqlPredicate from IMap values gives the ClassNotFoundException

I have setup hazelcast with 3 nodes in my system and i have connected with spring boot application , in spring boot application i am connecting through hazelcast-client.yaml

 hazelcast-client:
  user-code-deployment:
    enabled: true
    jarPaths:
      - buildlibshazelcast-demo-0.0.1-SNAPSHOT.jar
    classNames:
      - org.learning.cache.hazelcast.entity.Location
  network:
    cluster-members:
      - 127.0.0.1:5701
    smart-routing: false

I am able to connect succefully , but when i do SqlPredict query its not giving me the data, sample code snippet for the same

public List<Location> locations(Integer id, String accountId, String currency) {
        IMap<Integer, Location> locationIMap = hazelcastInstance.getMap("location");
        if (id != null && accountId != null && currency != null) {
            String query = "locationId = " + id + " AND accountId =" + accountId + " AND currency =" + currency;
            Collection<Location> result = locationIMap.values(new SqlPredicate(query));
            if (result != null) {
                return result.stream().collect(Collectors.toList());
            }
        }

The error i get when call this logic

2021-02-05 10:55:57,722 [ERROR] [hz.epic_sanderson.partition-operation.thread-1] [c.h.m.i.q.QueryPartitionOperation]: [10.1.0.9]:5701 [dev] [4.1.1] java.lang.ClassNotFoundException: org.learning.cache.hazelcast.entity.Location
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: org.learning.cache.hazelcast.entity.Location
        at com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:87) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:76) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:44) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:205) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:78) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:123) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:124) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:80) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:145) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:62) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.query.PartitionScanRunner$1.accept(PartitionScanRunner.java:110) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.query.PartitionScanRunner$1.accept(PartitionScanRunner.java:94) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.recordstore.DefaultRecordStore.forEach(DefaultRecordStore.java:234) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.recordstore.DefaultRecordStore.forEach(DefaultRecordStore.java:218) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.recordstore.DefaultRecordStore.forEachAfterLoad(DefaultRecordStore.java:247) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.query.PartitionScanRunner.run(PartitionScanRunner.java:94) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.query.CallerRunsPartitionScanExecutor.execute(CallerRunsPartitionScanExecutor.java:43) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.query.QueryRunner.runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(QueryRunner.java:219) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.query.QueryPartitionOperation.runInternal(QueryPartitionOperation.java:46) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:112) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:184) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:256) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:237) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:452) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:166) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:136) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123) [hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102) [hazelcast-all-4.1.1.jar:4.1.1]
Caused by: java.lang.ClassNotFoundException: org.learning.cache.hazelcast.entity.Location
        at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[?:?]
        at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[?:?]
        at com.hazelcast.internal.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:289) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.internal.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:249) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at com.hazelcast.internal.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:783) ~[hazelcast-all-4.1.1.jar:4.1.1]
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1995) ~[?:?]
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1862) ~[?:?]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2169) ~[?:?]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1679) ~[?:?]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:493) ~[?:?]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:451) ~[?:?]
        at com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:83) ~[hazelcast-all-4.1.1.jar

hazelcast version "hazelcast-all-4.1.1" spring boot version : 2.2.3.RELEASE

It seems that LocationEntity class might not present in any of the Hazelcast member , but not able to find how to fix this issue , appreciated for any help Thank you!!

question from:https://stackoverflow.com/questions/66059848/hazelcast-sqlpredicate-from-imap-values-gives-the-classnotfoundexception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is an error is in your hazelcast-client.yaml file.

The first line should read:

hazelcast-client:

not

hazelcast:

If you add this,

    @Bean
    public ClientConfig clientConfig() throws Exception {
        ClientConfig clientConfig = new YamlClientConfigBuilder("hazelcast-client.yaml").build();
        return clientConfig;
    }

You can print what's loaded, makes it easier to validate if the configuration you've specified is found.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...