【问题标题】:Error using Filter and Projection in Objectify Google Datastore在 Objectify Google Datastore 中使用过滤器和投影时出错
【发布时间】:2015-09-16 13:15:17
【问题描述】:

我正在尝试使用 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());
    }

这给了我一个错误:

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

基本上,我希望实现的是在实体上的不同查询旁边执行过滤器和项目查询。

如果查询有问题,请告诉我。

注意:rewardPoints 已编入索引。

【问题讨论】:

    标签: google-app-engine objectify


    【解决方案1】:

    我不了解 Objectify,但在 Google App Engine 数据存储区中,Projection query 将返回的结果限制为仅指定的列。使用distinctgrouping 相同,从错误消息来看,您似乎需要将rewardPoints 添加到投影中才能同时使用不等式过滤器和 distinct。

    【讨论】:

    • 太棒了!我在 Google App Engine 上使用 python,所以概念是一样的。我认为这只是将其转换为 Objectify API 的问题。
    【解决方案2】:

    看起来乔希是对的。我更改了查询,它运行良好。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      相关资源
      最近更新 更多