Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Objectify 4过滤器不工作_Java_Google App Engine_Objectify - Fatal编程技术网

Java Objectify 4过滤器不工作

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,但是当我使

我正在尝试执行一个简单的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
,但是当我使用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());
}