Domanda

Google cloud endpoints HTTP 500 error on delete

I generated a Google Cloud Endpoint class which game me the standard CRUD methods including the delete method:

public Member removeMember(@Named("id") Long id) {
    PersistenceManager mgr = getPersistenceManager();
    Member member = null;
    try {
        member = mgr.getObjectById(Member.class, id);
        mgr.deletePersistent(member);
    } finally {
        mgr.close();
    }
    return member;
}

However when I invoke a DELETE I get a HTTP 500 error returned:

HTTP ERROR 500

Problem accessing /_ah/spi/Members.removeMember. Reason:

com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Cannot read fields from a deleted object (through reference chain: com.mylodge.contracts.masonry.Member[\"degree\"])

How can I avoid this HTTP 500 error?

Aside: To me it seems illogical to return the deleted object anyway. Wouldn't a HTTP 200 OK be more appropriate?

UPDATE: I have tried return null instead, and tried making the method a VOID. But both of these yield an HTTP response of

500 No content to map to Object due to end of input
È stato utile?

Soluzione

If you don't want the object, don't return it. That's the easiest solution here. I'm going to suggest to the Google Plugin for Eclipse team that they change the template to not return the deleted object by default.

If you do want the deleted object, I think you're running into JDO's lazy loading. Your property degree is being loaded at serialization time. However, since the underlying datastore object is already deleted, it can't access it. You'll need to explicitly access the property before it gets deleted.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top