问题
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