Error using Filter and Projection in Objectify Goo

2019-08-22 15:24发布

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.

2条回答
闹够了就滚
2楼-- · 2019-08-22 16:03

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);
查看更多
Lonely孤独者°
3楼-- · 2019-08-22 16:14

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.

查看更多
登录 后发表回答