简体   繁体   English

在App Engine中按@id属性过滤Google Cloud Datastore实体

[英]Filter Google Cloud Datastore entities by @id property in App Engine

I am trying to to a Query in App Engine based on the @id property of the entities and I keep getting this error 我正在尝试基于实体的@id属性在App Engine进行查询,但不断收到此错误

java.lang.IllegalArgumentException: __ key __ filter value must be a Key java.lang.IllegalArgumentException:__键__过滤器值必须是一个键

this is how I am doing my Query 这就是我做查询的方式

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);

I want to get everything > the last comment id that is sent to the app engine method 我想获取所有信息>发送到应用程序引擎方法的最后一个注释ID

the id field in the entity is this 实体中的id字段是这个

@Id
Long id;

I tried using the id first but then I got an error saying that you cannot use a file who has @id and maybe I meant __ key __ 我先尝试使用id但随后出现错误消息,提示您不能使用具有@id的文件,也许我的意思是__ key __

so how do I execute this query? 那么如何执行此查询?

You need to use a Key , not an id, in your filter. 您需要在过滤器中使用Key而不是id。 You can create a Key from this id and then pass to your filter. 您可以根据此ID创建一个Key,然后传递到您的过滤器。

Note that unless you increment IDs yourself, they are not guaranteed to grow as you add more entities. 请注意,除非您自己增加ID,否则不能保证它们会随着您添加更多实体而增长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM