我正在 appengine 上使用 objectify,我尝试添加一个 cron 作业来删除所有早于一小时的临时实体:
Iterable<Key<Entry>> allKeys = ofy().load().type(Entry.class)
.filter("temporary", true)
.filter("createdAt", oneHourAgo).keys();
if(allKeys != null){
ofy().delete().keys(allKeys);
}
但在 appengine 服务器上执行 cron 作业时我总是遇到异常:
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Entry" ancestor="false" source="manual">
<property name="temporary" direction="asc"/>
<property name="createdAt" direction="asc"/>
</datastore-index>
有人知道为什么会发生这种情况吗?如果我删除,这项工作就可以进行:
.filter("createdAt", oneHourAgo)
最佳答案
当您将应用程序与开发服务器一起使用时,开发服务器会尝试找出您需要的索引并自动将它们放入索引定义文件中。由于您在 cron 作业中使用此查询,因此开发服务器无法在此为您提供帮助。您需要手动添加此索引的定义。
关于java - 对象化多个过滤器不适用于 cron 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25547895/