Error using Filter and Projection in Objectify Google Datastore

こ雲淡風輕ζ 提交于 2019-12-12 00:10:12

问题


I am trying to execute the below query using Objectify 5.1.8 :-

Query<Coupon> coupons = ObjectifyService.ofy().load().type(Coupon.class).filter("rewardPoints !=", "").project("code").distinct(true);
    for (Coupon coupon : coupons) {
        out.write(coupon.getCode());
    }

It is giving me an error :

java.lang.IllegalArgumentException: Inequality filter on rewardPoints must also be a group by property when group by properties are set.

Basically, what I wish to achieve is to perform a filter and project query alongside the distinct query on an entity.

Please let me know if there is something wrong with the query.

Note: rewardPoints is Indexed.


回答1:


I don't know about Objectify but in the Google App Engine Datastore a Projection query limits the returned results to just the column(s) specified. Using distinct is the same as grouping and from the error message, it looks like you need to add rewardPoints to the projection in order to use the inequality filter and distinct at the same time.




回答2:


Looks like Josh was right. I changed the query and it worked perfectly.

Query<Coupon> coupons = ObjectifyService.ofy().load().type(Coupon.class).filter("rewardPoints !=", "").project("rewardPoints").project("code").distinct(true);


来源:https://stackoverflow.com/questions/32609684/error-using-filter-and-projection-in-objectify-google-datastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!