【问题标题】:Google App Engine - Retrieving Entities - 503 Service Unavailable (Uploading works)Google App Engine - 检索实体 - 503 服务不可用(上传作品)
【发布时间】:2014-09-07 15:12:27
【问题描述】:

我已使用以下代码成功将实体上传到 Google App Engine:

    public class EndpointsTask extends AsyncTask<Void, Void, Void> {
    protected Void doInBackground(Void... params) {

        Entity entity = new Entity();

        Entityendpoint.Builder builder = new Entityendpoint.Builder(
                  AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                  null);

              builder = CloudEndpointUtils.updateBuilder(builder);
        Entityendpoint endpoint = builder.build();  
              try {
                  endpoint.insertEntity(entity).execute();
     }

现在,在我的 MainActivity 上,也使用 AsyncTask,我想做的是检索那些实体并在应用程序上显示它们。我基本上复制了上面的代码,但是我使用的是 getEntity 或 listEntity,而不是 isertEntity:

protected Void doInBackground(Void... params) {

            Entityendpoint.Builder builder = new Entityendpoint.Builder(
                      AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                      null);

                  builder = CloudEndpointUtils.updateBuilder(builder);

                  Entityendpoint endpoint = builder.build();


                    try {

                        endpoint.getEntity(5639445604728832L).execute();

                        String entityList = endpoint.listEntity().execute().toString());

                    } catch (IOException e) {
                        e.printStackTrace();
                    }

 }

无论我使用什么组合,我总是收到以下指向 getEntity 或 listEntity 行的错误:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable
System.err(1301): {
System.err(1301):   "code" : 503,
W/System.err(1301):   "errors" : [ {
W/System.err(1301):     "domain" : "global",
W/System.err(1301):     "message" : "",
W/System.err(1301):     "reason" : "backendError"
W/System.err(1301):   } ],
W/System.err(1301):   "message" : ""
W/System.err(1301): }
W/System.err(1301):     at      com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
W/System.err(1301): atcom.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
W/System.err(1301):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
W/System.err(1301):     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1049)
W/System.err(1301):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
W/System.err(1301):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
W/System.err(1301):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
W/System.err(1301):     at com.example.app.MainActivity$GetEntityList.doInBackground(MainActivity.java:304)
W/System.err(1301):     at com.example.app.MainActivity$GetEntityList.doInBackground(MainActivity.java:1)
W/System.err(1301):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
W/System.err(1301):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err(1301):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
W/System.err(1301):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err(1301):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err(1301):     at java.lang.Thread.run(Thread.java:841)

我在 Google App Engine 控制台上检查了 long,这是那里显示的错误:

Uncaught exception from servlet
java.io.IOException: 

com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException:

You have just   attempted to access field "touchedUsernames" yet this field was not detached when you detached the   object. Either dont access this field, or detach it when detaching the object. (through reference chain: com.example.app.Entity["touchedUsernames"])

我仍在尝试理解此错误消息。根据我的研究,上面显示的服务器上的日志与我的实体的变量设置不正确有关。

这是它的定义方式:

@Entity
public class Entity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String description;
private Blob bmp;
private String username;
private long touched;
private boolean obscene;


@ElementCollection private Set<String> touchedUsernames = new HashSet<String>(); 
@ElementCollection private Set<String> obsceneUsernames = new HashSet<String>(); 

任何想法我应该如何更新上面的实体以摆脱错误?

谢谢!

【问题讨论】:

    标签: java android google-app-engine google-cloud-datastore


    【解决方案1】:

    找到答案了!而不是@ElementCollection,我必须使用@Basic 注解!

    @Entity
    

    公共类实体{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String title;
    private String description;
    private Blob bmp;
    private String username;
    private long touched;
    private boolean obscene;
    
    
    @Basic private Set<String> touchedUsernames = new HashSet<String>(); 
    @Basic private Set<String> obsceneUsernames = new HashSet<String>(); 
    

    【讨论】:

      猜你喜欢
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      相关资源
      最近更新 更多