【问题标题】:Filter Google Cloud Datastore entities by @id property in App Engine在 App Engine 中按 @id 属性过滤 Google Cloud Datastore 实体
【发布时间】:2016-06-21 19:39:19
【问题描述】:

我正在尝试基于实体的@id 属性在App Engine 中进行查询,但我不断收到此错误

java.lang.IllegalArgumentException: __ key __ filter value must be a Key

这就是我的查询方式

Filter f1 = new FilterPredicate("personId", FilterOperator.EQUAL,personId);
Filter f2 = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN,newestCommentId);

Filter filter = CompositeFilterOperator.and(f1,f2);


Query<Record> query = ofy().load().type(Record.class).filter(filter)
                .limit(limit).order("-"+ Entity.KEY_RESERVED_PROPERTY);

我想获取所有&gt; 发送到应用引擎方法的最后评论 id

实体中的id字段是这个

@Id
Long id;

我首先尝试使用id,但随后我收到一条错误消息,提示您不能使用具有@id 的文件,也许我的意思是__ 键__

那么我该如何执行这个查询呢?

【问题讨论】:

    标签: google-app-engine google-cloud-platform objectify google-cloud-datastore


    【解决方案1】:

    您需要在过滤器中使用use a Key,而不是 id。您可以从此 id 创建一个 Key,然后传递给您的过滤器。

    请注意,除非您自己增加 ID,否则不能保证它们会随着您添加更多实体而增长。

    【讨论】:

    • 所以 id 是唯一的,但不一定像 SQL 主键那样按顺序排列?
    猜你喜欢
    • 2015-07-25
    • 2015-07-25
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多