在 App Engine 中按 @id 属性 过滤 Google Cloud Datastore 实体
Filter Google Cloud Datastore entities by @id property in App Engine
我正在尝试根据实体的 @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);
我想获取所有内容>
发送到应用引擎方法的最后一条评论 ID
实体中的id字段是这个
@Id
Long id;
我先尝试使用 id
,但后来我收到一条错误消息,提示您不能使用具有 @id 的文件,也许我的意思是 __ key __
那么我该如何执行这个查询呢?
您需要在过滤器中 use a Key,而不是 ID。您可以从这个 ID 创建一个密钥,然后传递给您的过滤器。
请注意,除非您自己增加 ID,否则不能保证它们会随着您添加更多实体而增加。
我正在尝试根据实体的 @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);
我想获取所有内容>
发送到应用引擎方法的最后一条评论 ID
实体中的id字段是这个
@Id
Long id;
我先尝试使用 id
,但后来我收到一条错误消息,提示您不能使用具有 @id 的文件,也许我的意思是 __ key __
那么我该如何执行这个查询呢?
您需要在过滤器中 use a Key,而不是 ID。您可以从这个 ID 创建一个密钥,然后传递给您的过滤器。
请注意,除非您自己增加 ID,否则不能保证它们会随着您添加更多实体而增加。