Google App Engine - 检索实体 - 503服务不可用(上传工作)

时间:2014-09-07 15:12:28

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

我使用以下代码成功将实体上传到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,我想做的是检索那些在app上显示它们的实体。我基本上复制了上面的代码,但是我使用的是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控制台上检查了很长时间,这是显示在那里的错误:

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>(); 

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

谢谢!

1 个答案:

答案 0 :(得分:2)

找到答案!而不是@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>();