简体   繁体   English

数据存储区查询返回null

[英]Datastore Query returns null

I am trying to retrieve a sorted list of the players scores from a datastore Entity of type"User" After executing: 我正在尝试从“用户”类型的数据存储实体中检索球员得分的排序列表:

 List<User> entities = ofy().load().type(User.class).order("-score").list();

Knowing that I indexed the "score" attribute. 知道我索引了“得分”属性。 Here is the "User.class" 这是“ User.class”

@Id String userName;
     String password;
    @Index int score;

The entities seem to be null and i can't get the entities details.What am I missing??? 实体似乎为空,我无法获取实体详细信息。我缺少什么????

I am still working on that I managed to modify the method to: 我仍在努力设法将方法修改为:

 @Override
  public User display(){
     List<User> list = ofy().load().type(User.class).order("-score").limit(5).list();
     User u= list.get(list.size()-1);
      if(!u.getUserName().equals(null))  
        return  u;
      return null;
  }

I managed to get rid of the "null" value by checking the username field but the return value was always the first user in the entity no matter how I changed list.get(index).I tried different values for index but always received the first user and can't retrieve the others. 通过检查用户名字段,我设法摆脱了“空”值,但是无论我如何更改list.get(index),返回值始终是实体中的第一个用户。我尝试使用不同的index值,但始终收到第一个用户,无法检索其他用户。 Hoping to get an answer that would solve the problem. 希望得到可以解决问题的答案。

The entities are stored in the database as follows: 实体存储在数据库中,如下所示:

public User registerAccount(String username, String password,String confirm) {
        User user = ofy().load().type(User.class).id(username).get();



        if(user == null){
            if(password.contains(" "))          
                return null;            
            if(password.compareTo(confirm)!=0)
                return null;

            else{
            user = new User(username,password,0);
            ofy().save().entity(user).now();
            return user;
            }
         }

        else
        {
            return null;
        }
  } 

So is there any problem in using ofy().save()... rather than datastore.put()... I am wondering if that would affect that as the score is not found in the datastore indexes. 那么使用ofy()。save()...而不是datastore.put()...有什么问题吗?我想知道是否会因为在数据存储区索引中找不到分数而影响这一点。

One possible reason is that @Index annotation on "score" property was not there from the beginning. 一个可能的原因是,从一开始就没有在“ score”属性上使用@Index注释。 Users that were added before update, can't be fetched by .order("-score") command. .order(“-score”)命令无法提取在更新之前添加的用户。

Another possible thing is trivial but common! 另一个可能的事情是琐碎的,但却很常见! It is your class naming ("User"). 这是您的类命名(“用户”)。 Do you have correct import? 您输入正确吗? GAE also has quite common class com.google.appengine.api.users.User that is used for authentication. GAE还具有用于认证的通用类com.google.appengine.api.users.User。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 子数据存储区实体的键返回为null - key of child datastore entity returns as null 订购结果时,数据存储区查询不返回任何数据 - Datastore query returns no data when ordering result 立即查询已保存的实体有时会返回null-数据存储区 - Querying immediately for saved entity returns null sometimes - datastore Appengine Datastore查询在事务内返回不同的结果 - Appengine Datastore query returns different result inside transaction 带过滤器的AppEngine数据存储区查询永远不会返回结果(Go) - AppEngine Datastore query with filter never returns results (Go) NDB查询返回零结果。 数据存储区显示结果 - NDB query returns zero results. Datastore shows the result 为什么我的GAE数据存储区查询返回的游标为空? - Why is the cursor returned from my GAE datastore query null? 为什么google datastore第二个查询返回修改后的实例(第一次查询后没有调用put)? - why does google datastore second query returns modified instance (without calling put after first query)? Datastore Viewer控制台中的GQL基本查询返回“空名称空间中没有结果”。 - GQL basic query in Datastore Viewer console returns “No results in Empty namespace.” App Engine:检查我的数据存储区查询是否返回任何结果的最快方法是什么? - App Engine: What is the fastest way to check if my datastore query returns any result?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM