简体   繁体   English

Google App Engine(Java)数据存储区检索不起作用

[英]Google app engine(java) datastore retrieve not working

I am not able to retrieve the Entities from Data Store . 我无法从数据存储中检索实体。

Following : Google Code Lab I made this function : 以下: Google Code Lab我实现了此功能:

   @SuppressWarnings("deprecation")
   public static Iterable<Entity> listEntities(String kind, String searchBy,String searchFor) {
   com.google.appengine.api.datastore.DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
   Query q = new Query(kind);

   if (searchFor != null && !"".equals(searchFor)) 
        {
            q.addFilter(searchBy, FilterOperator.EQUAL, searchFor);
        }

    PreparedQuery pq = ds.prepare(q);

    return pq.asIterable();

    }

then calling this to get the values : 然后调用它来获取值:

    for(Entity u:listEntities("Upload","UID","ratan"))
         {
             String uid = (String) u.getProperty("url");
             System.out.println("#1##"+uid);
         }

But it does not prints any value !!! 但是它不会输出任何值! where I went wrong . 我哪里出错了。

this is my Datastore instance for "Upload" Entity 这是我的“上传”实体的数据存储区实例

在此处输入图片说明

Even this doesn't works: 即使这样也不起作用:

for(Entity u:listEntities("Upload",null,null))
{
  String uid = (String) u.getProperty("url");
  System.out.println("#1##"+uid);
}

You have to define index for this entity. 您必须为此实体定义索引。 How to define index in app engine please look at this link: 如何在App Engine中定义索引,请查看以下链接:

https://developers.google.com/appengine/docs/java/config/indexconfig https://developers.google.com/appengine/docs/java/config/indexconfig

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM