Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Apache Ignite未能找到SQL表_Java_Spring Boot_Ignite - Fatal编程技术网

Java Apache Ignite未能找到SQL表

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>();

我正在开发一个spring应用程序来连接ApacheIgnite缓存以获取记录。首先,我运行DataNode缓存代码(如下所述)从数据库中获取所有数据。接下来,当我尝试运行客户端代码以查询不同应用程序中的缓存时。我得到的错误是“未能找到类型为Person的SQL表”

DataNode缓存代码:

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) {
    
        }