我写这些代码
Query q = pm.newQuery(User.class);
q.setFilter("textPosts != null"); // textPosts is a Text
List<User> users = (List<User>) q.execute();
resp.getWriter().println("user num: " + users.size());
我得到了
user num: 0
我确信这个数字应该大于0 我可能会错过一些重要的事情 提前谢谢!
答案 0 :(得分:2)
Querying Unindexed properties:
A query with a filter or sort order on a property will never match an entity with that property unindexed
因此找不到您的实体,因为Text属性从未编入索引。
这也是相关的(但在你的情况下,文字是无索引的) - entities with non-existing properties are not found with queries:
The App Engine datastore distinguishes between an entity without a given property and an entity with a null value for a property. JDO does not support this distinction: every field of an object has a value, possibly null.
因此,如果你有一个没有属性的实体,那么找不到查询,因为query requires that the property exists。
答案 1 :(得分:0)
可能因为Text
不会出于查询目的而被编入索引,因为它在javadoc中指定:http://code.google.com/intl/en/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Text.html
顺便说一句,我确信在这种情况下它必须抛出异常。