Getting CacheException when querying in ignite

给你一囗甜甜゛ 提交于 2019-12-24 00:25:49

问题


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.

Following is the code for my implementation:

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";
}

回答1:


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



来源:https://stackoverflow.com/questions/39875317/getting-cacheexception-when-querying-in-ignite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!