gpt4 book ai didi

java - 如何解决ignitecheckedException : make sure all objects in cache configuration are serializable

转载 作者:行者123 更新时间:2023-12-02 11:15:53 24 4
gpt4 key购买 nike

我正在使用 Spring Boot 运行 Ignite。我的目的是在 Ignite 中对 BinaryObject 执行 SqlFieldQuery,提到我没有任何实体类,在运行时使用 QueryEntity 创建实体。这是我的以下代码:

 CacheConfiguration<Integer, BinaryObject> cachecfg = new CacheConfiguration<>();   
cachecfg.setQueryEntities(new ArrayList<QueryEntity>()
{
{

QueryEntity e = new QueryEntity();
e.setKeyType("java.lang.Integer");
e.setValueType("BinaryTest");
e.setFields(new LinkedHashMap<String, String>() {
{
put("name", "java.lang.String");
}
});
add(e);
}
});
cachecfg.setName("MY_CACHE");
IgniteCache<Integer, BinaryObject> ignitecache = igniteInstance.createCache(cachecfg).withKeepBinary();
BinaryObjectBuilder builder = igniteInstance.binary().builder("BinaryTest");
builder.setField("name", "Test");
ignitecache.put(1, builder.build());
QueryCursor<List<?>> query = ignitecache.query(new SqlFieldsQuery("select name from BinaryTest"));
System.out.println(query.getAll());

当我运行此代码时,出现错误:

class org.apache.ignite.IgniteCheckedException: Failed to validate cache 
configuration (make sure all objects in cache configuration are
serializable): MY_CACHE

我可能缺少一些序列化配置。有什么问题吗?

最佳答案

摆脱双括号初始化,在这种情况下,您最终会得到一个匿名类,它是具有实例初始值设定项的 ArrayList 的子类。匿名类始终包含对封闭类的引用,在您的情况下,它试图被序列化。

所以选择:

    CacheConfiguration<Integer, BinaryObject> cachecfg = new CacheConfiguration<>();

QueryEntity e = new QueryEntity();
e.setKeyType("java.lang.Integer");
e.setValueType("BinaryTest");

LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("name", "java.lang.String");
e.setFields(map);

ArrayList<QueryEntity> list = new ArrayList<QueryEntity>();
list.add(e);
cachecfg.setQueryEntities(list);
cachecfg.setName("MY_CACHE");
IgniteCache<Integer, BinaryObject> ignitecache = igniteInstance.createCache(cachecfg).withKeepBinary();

关于java - 如何解决ignitecheckedException : make sure all objects in cache configuration are serializable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50284878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com