您不能在两个不同的字段上执行 OR。这是来自文档的片段:
在 JDOQL 字符串语法中,您可以使用 || 分隔多个过滤器。(逻辑“或”)和 &&(逻辑“与”),但请记住 || 只能在它分隔的过滤器都具有相同的字段名称时使用。换句话说,|| 只有在它分离的过滤器可以组合成一个 contains() 过滤器的情况下才合法:
// legal, all filters separated by || are on the same field
Query query = pm.newQuery(Employee.class,
"(lastName == 'Smith' || lastName == 'Jones')" +
" && firstName == 'Harold'");
// not legal, filters separated by || are on different fields
Query query = pm.newQuery(Employee.class,
"lastName == 'Smith' || firstName == 'Harold'");
解决此问题的一种方法可能是将您的 a 和 b 存储在列表中。如果您有一个名为 foo 的项目列表,则可以在 foo = 关键字的地方进行查询,如果 foo 中的任何项目匹配,您将在结果中返回该对象。您对 a 和 b 的含义不多说,所以我不知道这是否适合您:)
更新:
public class Example {
String firstName;
String lastName;
List<String> allNames;
public Example(String first, String last){
firstName = first;
lastName = last;
allNames = new ArrayList<String>();
allNames.add(first);
allNames.add(last);
}
}
有了类似的东西,您就可以在“allNames == 'Smith' || allNames=='Jones'”的地方进行查询。