在 ignite 中查询时获取 CacheException
Getting CacheException when querying in ignite
我是 Ignite 新手,实际上使用 spring 引导应用程序与 Ignite 交互。我已经将缓存摄取到 ignite 中,并通过键从 ignite 中获取了缓存。但是,如果我尝试通过查询 API 获取缓存,则会出现以下异常。
[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.
以下是我的实现代码:
当我调用此方法时出现上述异常
@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";
}
这工作正常,我正在从 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 架构和索引 - 如果您想要 运行 查询,这是必需的。详情请参阅此页面:https://apacheignite.readme.io/docs/sql-queries
我是 Ignite 新手,实际上使用 spring 引导应用程序与 Ignite 交互。我已经将缓存摄取到 ignite 中,并通过键从 ignite 中获取了缓存。但是,如果我尝试通过查询 API 获取缓存,则会出现以下异常。
[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.
以下是我的实现代码:
当我调用此方法时出现上述异常
@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";
}
这工作正常,我正在从 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 架构和索引 - 如果您想要 运行 查询,这是必需的。详情请参阅此页面:https://apacheignite.readme.io/docs/sql-queries