TGCBraun
TGCBraun

Reputation: 95

Google App Engine - Retrieving Entities - 503 Service Unavailable (Uploading works)

I'm successfuly uploading entities to Google App Engine using the following code:

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

Now, on my MainActivity, using also a AsyncTask, wha I want to do is to retrieve those entities do display them on the app. I basically copied the code above, but instead of isertEntity, I'm using getEntity or listEntity:

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

 }

Whatever combination I use, I ALWAYS get the following error pointing to the getEntity or listEntity line:

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)

I checked the long on Google App Engine Console, and this is the error displayed there:

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"])

I'm still trying to understand this error message. From what I've researched, the Log showed above on the server has something to do with the variables of my entity not being correctly set.

Here's how it's defined:

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

Any ideas how should I update the Entity above to get rid of the error?

Thanks!

Upvotes: 2

Views: 1050

Answers (1)

TGCBraun
TGCBraun

Reputation: 95

Found the answer! Instead of @ElementCollection, I have to use the @Basic annotation!

@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;


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

Upvotes: 2

Related Questions