Google App Engine投影查询返回0结果 [英] Google App Engine projection query returns 0 results

查看:153
本文介绍了Google App Engine投影查询返回0结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行投影查询,以便从我的数万个实体中的每个实体中获取多个属性。我已阅读并遵循文档,但我的查询未返回任何内容结果。我甚至将我的投影简化为仅投影单个属性,实体的ID字段,但仍然得到0结果。这是我的简化代码:

I am trying to perform a projection query in order to fetch several properties from each entity in my datastore of over ten thousand entities. I have read and followed the documentation, but my query is not returning any results. I've even simplified my projection down to only projecting a single property, the entity's ID field, but still get 0 results. Here is my simplified code:

Query q = new Query("MyEntity");
q.addProjection(new PropertyProjection("entityId", Long.class));
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(q);
int count = pq.countEntities(FetchOptions.Builder.withLimit(1000));
log.info("query contains " + count + " items.");

当我运行此代码时, count equals 0.如果我只删除第二行以使查询没有投影, count 等于1000。

When I run this code, count equals 0. If I simply remove the second line so that the query has no projections, count equals 1000.

I我在我的应用中使用 Objectify ,但我使用的是GAE低级API投影查询因为我使用的是Objectify v3,它不支持投影查询。更改我的代码以支持Objectify v4会有很多工作。

I am using Objectify in my app, but I am using the GAE low-level API for projection queries because I'm using Objectify v3, which doesn't support projection queries. It would be a lot of work to change my code to support Objectify v4.

entityId 字段我是投影在我的Objectify实体对象中看起来像这样:

The entityId field I'm projecting looks like this in my Objectify entity object:

@Id Long entityId;


推荐答案

所以事实证明我只是投影的简化案例ID属性原来是问题所在。当我在任何其他属性字段上测试相同的代码时,投影查询可以正常工作。

So it turns out my simplified case of projecting only the ID property turned out to be the problem. When I tested the same code on any other property field, the projection query works.

创建投影查询时,不应该投影ID属性。它仍包含在生成的实体中,但在预测中包含它会导致查询没有结果。 ID属性的存储方式与实体中其他属性字段的存储方式不同。

When creating projection queries, the ID property should not be projected. It is still included in the resulting entity, but including it in the projections causes the query to turn up no results. The ID property is not stored the same way as the other property fields in the entity.

这篇关于Google App Engine投影查询返回0结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆