本文介绍了在ignite中查询时获取CacheException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ignite的新手,实际上是使用spring boot应用程序与ignite交互的。我将缓存吸收到ignite中,并通过键从ignite获取了缓存。但是,如果我尝试通过查询API获取缓存,则会收到以下异常。

I am new to Ignite and actually using spring boot application to interact with ignite. I have ingested cache into ignite and fetched cache from ignite through keys. But if i try to fetch cache through query API i am getting the following exception.

[16:56:55,225][SEVERE][http-nio-8080-exec-2][[dispatcherServlet]] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.cache.CacheException: Indexing is disabled for cache: testCache. Use setIndexedTypes or setTypeMetadata methods on CacheConfiguration to enable.] with root cause javax.cache.CacheException: Indexing is disabled for cache: testCache. Use setIndexedTypes or setTypeMetadata methods on CacheConfiguration to enable.

以下是我的实现代码:

当我调用此方法时,出现上述异常

When i invoke this method i am getting the above exception

@RequestMapping(value = "/query/cache", produces = "text/html")
private String queryCache(Model model) {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        // Load cache with data from the database.
        CacheConfiguration<Long, IgnitePerson> cfg = new CacheConfiguration<>("testCache");
        IgniteCache<Long, IgnitePerson> cache = ignite.getOrCreateCache(cfg);
        SqlQuery<Long, IgnitePerson> query = new SqlQuery<>(IgnitePerson.class, "select * from IgnitePerson");
        List<Entry<Long, IgnitePerson>> list = cache.query(query).getAll();
        personsList = new ArrayList<>();
        for (Entry<Long, IgnitePerson> entry : list) {
            personsList.add(entry.getValue());
        }
        model.addAttribute("persons", personsList);
    }
    return "cacheresults";
}

这很好,而且我正在从缓存中获取缓存

This works fine and i am getting cache from ignite

@RequestMapping(value = "/read/cache", produces = "text/html")
private String readCache(Model model) {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        // Load cache with data from the database.
        CacheConfiguration<Long, IgnitePerson> cfg = new CacheConfiguration<>("testCache");
        IgniteCache<Long, IgnitePerson> cache = ignite.getOrCreateCache(cfg);
        Set<Long> keys = new TreeSet<>();
        keys.add((long) 1);
        keys.add((long) 2);
        Map<Long, IgnitePerson> map = cache.getAll(keys);
        personsList = new ArrayList<>(map.values());
        model.addAttribute("persons", personsList);
    }
    return "cacheresults";
}


推荐答案

您没有配置SQL模式和索引-如果要运行查询,这是必需的。请参阅此页面以获取详细信息:

You did not configure SQL schema and indexing - this is required if you want to run queries. Refer to this page for details: https://apacheignite.readme.io/docs/sql-queries

这篇关于在ignite中查询时获取CacheException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:06