Java Objectify 4过滤器不工作
我正在尝试执行一个简单的JUnit测试来执行如下查询:Java Objectify 4过滤器不工作,java,google-app-engine,objectify,Java,Google App Engine,Objectify,我正在尝试执行一个简单的JUnit测试来执行如下查询: Resource result = ofy().load().type(Resource.class).filter("raw =", "/Bob/-/userId/-/").first().get(); if (result != null){ System.out.println("Resulting Resource raw =" + result.getRaw()); } 上面的查询结果为null,但是当我使
Resource result = ofy().load().type(Resource.class).filter("raw =",
"/Bob/-/userId/-/").first().get();
if (result != null){
System.out.println("Resulting Resource raw =" + result.getRaw());
}
上面的查询结果为null
,但是当我使用id(一个长类型)进行查询时,我会得到结果。当我坚持我要尝试的实体时
查询我记录了@Id
,值为1
,因此我使用Id
进行了查询以检查:
Resource result = ofy().load().type(Resource.class).filter("raw =",
"/Bob/-/userId/-/").first().get();
if (result != null){
System.out.println("Resulting Resource raw =" + result.getRaw());
}
Resource result =
ofy().load().type(Resource.class).filter("id =", 1).first().get();
if (result != null){
System.out.println("Resulting Resource raw =" + result.getRaw());
}
结果是
result.getRaw()
是/Bob/-/userId/-/
,这真的很奇怪,从我的第一次查询开始,结果应该不是null
?检查该字段上是否有@Index,如果尝试选择没有索引的by字段,即使它在那里,也会得到null。
Resource result = ofy().load().type(Resource.class).filter("raw =",
"/Bob/-/userId/-/").first().get();
if (result != null){
System.out.println("Resulting Resource raw =" + result.getRaw());
}
当然,在几个字段上,您需要对所有字段进行索引
Resource result = ofy().load().type(Resource.class).filter("raw =",
"/Bob/-/userId/-/").first().get();
if (result != null){
System.out.println("Resulting Resource raw =" + result.getRaw());
}
*多个字段的索引将放在datastore-indexes.xml中您知道它是否应该在开发中工作吗?Addin
@Index
对我没有帮助:(别忘了,根据您要查询的数据,“datastore Index.xml”文件中可以有多个索引(它对大多数nosql db都是一样的)!
Resource result = ofy().load().type(Resource.class).filter("raw =",
"/Bob/-/userId/-/").first().get();
if (result != null){
System.out.println("Resulting Resource raw =" + result.getRaw());
}