Java Apache Ignite未能找到SQL表
我正在开发一个spring应用程序来连接ApacheIgnite缓存以获取记录。首先,我运行DataNode缓存代码(如下所述)从数据库中获取所有数据。接下来,当我尝试运行客户端代码以查询不同应用程序中的缓存时。我得到的错误是“未能找到类型为Person的SQL表” DataNode缓存代码:Java Apache Ignite未能找到SQL表,java,spring-boot,ignite,Java,Spring Boot,Ignite,我正在开发一个spring应用程序来连接ApacheIgnite缓存以获取记录。首先,我运行DataNode缓存代码(如下所述)从数据库中获取所有数据。接下来,当我尝试运行客户端代码以查询不同应用程序中的缓存时。我得到的错误是“未能找到类型为Person的SQL表” DataNode缓存代码: CacheConfiguration<String, Person> personCache = new CacheConfiguration<String, Person>();
CacheConfiguration<String, Person> personCache = new CacheConfiguration<String, Person>();
personCache.setName("person:cache");
personCache.setRebalanceMode(CacheRebalanceMode.SYNC);
personCache.setReadThrough(true);
personCache.setWriteThrough(false);
personCache.setWriteBehindEnabled(false);
personCache.setCacheMode(CacheMode.PARTITIONED);
personCache.setIndexedTypes(String.class, Person.class);
personCache.setEvictionPolicy(new LruEvictionPolicy<>(100000));
personCache.setOnheapCacheEnabled(true);
personCache.setCacheStoreFactory(FactoryBuilder.factoryOf(PersonCacheStore.class));
configuration.setCacheConfiguration(personCache);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500"));
tcpDiscoverySpi.setIpFinder(ipFinder);
configuration.setDiscoverySpi(tcpDiscoverySpi);
IgniteCache<String, Person> personCache = ignite.getOrCreateCache("person:cache");
personCache.loadCache(null);
}
个人电脑商店:
public class PersonCacheStore implements CacheStore<String, Person> {
public Person load(String name) throws CacheLoaderException {
// code to load data from DB.
}
public void loadCache(IgniteBiInClosure<String, Person> clo, Object... arg1) throws CacheLoaderException {
// code to load data from DB.
}
公共类PersonCacheStore实现CacheStore{
公共人物加载(字符串名称)引发CacheLoaderException{
//从数据库加载数据的代码。
}
公共void loadCache(IgniteBiInClosure clo,对象…arg1)引发CacheLoaderException{
//从数据库加载数据的代码。
}
}
用于查询缓存的客户端代码:
IgniteConfiguration configuration = new IgniteConfiguration();
configuration.setClientMode(true);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500"));
tcpDiscoverySpi.setIpFinder(ipFinder);
configuration.setDiscoverySpi(tcpDiscoverySpi);
Ignite ignite = Ignition.start(configuration);
IgniteCache<String, Person> cache = ignite.getOrCreateCache("person:cache");
SqlQuery<String, Person> qry2 = new SqlQuery<String, Person>(Person.class,
"select * from Person where name = ?");
qry2.setArgs("Ram");
List<Entry<String, Person>> res = cache.query(qry2).getAll();
for (Entry<String, Person> entry : res) {
}
IgniteConfiguration配置=新的IgniteConfiguration();
configuration.setClientMode(true);
TcpDiscoverySpi TcpDiscoverySpi=新的TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder=新的TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList(“127.0.0.1:47500”);
tcpDiscoverySpi.setIpFinder(ipFinder);
setDiscoverySpi(tcpDiscoverySpi);
点火=点火启动(配置);
IgniteCache cache=ignite.getOrCreateCache(“person:cache”);
SqlQuery qry2=新的SqlQuery(Person.class,
“从姓名=?”的人员中选择*”;
qry2.setArgs(“Ram”);
List res=cache.query(qry2.getAll();
用于(条目:res){
}
请帮助我解决此问题。不清楚如何在
DataNode
上创建缓存。您创建了一个CacheConfiguration
对象,然后将其添加到Ignite configuration中,但实际上,在启动节点后,这种情况似乎会发生。如果是这种情况,那么缓存是使用默认设置创建的,因此不知道SQL配置
有两个选项需要修复:
Ignition.start()
之前,请确保已完全创建IgniteConfiguration
(包括CacheConfiguration
)。然后使用ignite.cache(“person:cache”)
获取缓存;如果您这样做而不是使用getOrCreateCache
,那么您将得到null
,而不是配置不正确的缓存,以防您搞乱某些东西,因此更容易找到问题CacheConfiguration
作为IgniteConfiguration
的一部分提供,而是使用getOrCreateCache
提供配置对象而不仅仅是名称来创建缓存不清楚如何在
DataNode
上创建缓存。您创建了一个CacheConfiguration
对象,然后将其添加到Ignite configuration中,但实际上,在启动节点后,这种情况似乎会发生。如果是这种情况,那么缓存是使用默认设置创建的,因此不知道SQL配置
有两个选项需要修复:
Ignition.start()
之前,请确保已完全创建IgniteConfiguration
(包括CacheConfiguration
)。然后使用ignite.cache(“person:cache”)
获取缓存;如果您这样做而不是使用getOrCreateCache
,那么您将得到null
,而不是配置不正确的缓存,以防您搞乱某些东西,因此更容易找到问题CacheConfiguration
作为IgniteConfiguration
的一部分提供,而是使用getOrCreateCache
提供配置对象而不仅仅是名称来创建缓存这是文档中的示例:
准确地解决您的问题。这是文档中的示例:
准确地解决您的问题。这应该是一条评论这应该是一条评论
IgniteConfiguration configuration = new IgniteConfiguration();
configuration.setClientMode(true);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500"));
tcpDiscoverySpi.setIpFinder(ipFinder);
configuration.setDiscoverySpi(tcpDiscoverySpi);
Ignite ignite = Ignition.start(configuration);
IgniteCache<String, Person> cache = ignite.getOrCreateCache("person:cache");
SqlQuery<String, Person> qry2 = new SqlQuery<String, Person>(Person.class,
"select * from Person where name = ?");
qry2.setArgs("Ram");
List<Entry<String, Person>> res = cache.query(qry2).getAll();
for (Entry<String, Person> entry : res) {
}