Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.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 谷歌云结果的返回大小是多少?为什么它不像eclipse那样工作?_Java_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Java 谷歌云结果的返回大小是多少?为什么它不像eclipse那样工作?

Java 谷歌云结果的返回大小是多少?为什么它不像eclipse那样工作?,java,google-app-engine,google-cloud-datastore,Java,Google App Engine,Google Cloud Datastore,好的,我有这段代码&它在eclipse中运行良好 public static long getPropertyMaxIDStronglyConsistent(String entityName, String propertyName, Key parentKey){ // Order alphabetically by property name: //Key parentKey=KeyFactory.createKey(parentEntity

好的,我有这段代码&它在eclipse中运行良好

public static long getPropertyMaxIDStronglyConsistent(String entityName, String propertyName, Key parentKey){
            // Order alphabetically by property name:
            //Key parentKey=KeyFactory.createKey(parentEntityName, parentName);
            Query q = new Query(entityName, parentKey).setAncestor(parentKey)
                            .addSort(propertyName, SortDirection.DESCENDING);

            //List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
            List<Entity> results = datastore.prepare(q)
                            .asList(FetchOptions.Builder.withLimit(5));        
            if(results.size()>0){
                Entity e=results.get(0);
                long maxID=(Long)e.getProperty(propertyName);


                return maxID;

            }
            else{
                return 0;
            }

    }
public静态长getPropertyMaxIDStronglyConsistent(String entityName、String propertyName、Key parentKey){
//按属性名称的字母顺序排列:
//Key parentKey=KeyFactory.createKey(parentEntityName,parentName);
查询q=新查询(entityName,parentKey).SetAncenter(parentKey)
.addSort(propertyName、SortDirection.DESCENDING);
//列表结果=datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
列表结果=数据存储。准备(q)
.asList(FetchOptions.Builder.withLimit(5));
如果(results.size()>0){
实体e=结果。获取(0);
long maxID=(long)e.getProperty(propertyName);
返回maxID;
}
否则{
返回0;
}
}
然而,在部署到谷歌应用程序引擎后,它把一切都搞砸了

根据我的研究,当我们得到
List results=datastore.prepare(q).asList(FetchOptions.Builder.withLimit(5)),Google似乎会返回额外的行与MYSQL和JDBC驱动程序不同


例如,如果实际表有2行,它将返回3行&如果我们
Entity e=results.get(0)它不知何故没有显示任何内容。

在多年的生产过程中,我从未见过它返回错误数量的实体。在定义查询时,您使用了两次
parentKey
。这是不必要的-您基本上设置了两次祖先键。但是如果“return(results.size()”,那么查询也没有错,如果它错了,为什么它在eclipse中工作得很好?(1)它没有错。没必要。(2) 方法的名称意味着您需要强一致性。查询的一致性不强。