【问题标题】:Java GAE: Can I filter by comparing the properties of entities?Java GAE:我可以通过比较实体的属性进行过滤吗?
【发布时间】:2015-08-02 15:28:55
【问题描述】:

我需要查询具有相同属性的实体,例如:

class Relation {
  Integer a;
  Integer b;
}

Query q = pm.newQuery(Relation.class);
q.setFilter("a == b");

上面的查询返回空列表,我还没有找到任何方法来完成这个任务。

【问题讨论】:

  • 清楚地查看日志会告诉您在数据存储中实际调用了什么查询

标签: java google-app-engine filter jdo


【解决方案1】:

查看 the documentation 的数据存储查询,它明确指出:

The property value must be supplied by the application; it cannot refer to or be calculated in terms of other properties.

所以你想做的事是不可能的。

你可以做的一件事是:

1- 向您的实体添加第三个属性(比如一个名为“equals”的布尔值)。

2- 每当您更新实体时,都会检查 a == b。

3- 根据 2 中的检查更新“等于”。

4- 要查询,请查看等于 == true 的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多