Objects not preserving the use of Objectify and GAE

I am trying to save an object and verify that it is saved right after, and it does not seem to work.

Here is my object

import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; @Entity public class PlayerGroup { @Id public String n;//sharks public ArrayList<String> m;//members [39393,23932932,3223] } 

Here is the code to save, then try downloading right after.

  playerGroup = new PlayerGroup(); playerGroup.n = reqPlayerGroup.n; playerGroup.m = reqPlayerGroup.m; ofy().save().entity(playerGroup).now(); response.i = playerGroup; PlayerGroup newOne = ofy().load().type(PlayerGroup.class).id(reqPlayerGroup.n).get(); 

But the newOne object is null. Although I just finished this. What am I doing wrong?

- Update-- If I try later (for example, after a few minutes), sometimes I see an object, but not immediately after saving. Is it related to high replication storage?

+8
google-app-engine loading objectify
source share
1 answer

There was the same behavior some time ago and asked a question about google groups - objectify

Here is the answer I received:

 You are seeing the eventual consistency of the High-Replication Datastore. There has been a lot of discussion of this exact subject on the Objecify list in google groups , including several links to the Google documentation on the subject. Basically, any kind of query which does not include an ancestor() may return results from a stale view of the datastore. Jeff 

I also got another good answer to deal with the behavior.

To delete, request for keys and then batch receive objects. Make sure your recipients are set up for strong consistency (although I believe this is the default). The get package should return null for remote objects. When you add it, it gets a little harder. Index updates may take a few seconds. AFAIK, there are three ways out of this: 1; Use preliminary results (completely excluding the query). If your next view is custom newly created objects, save the list of these keys with the entity user and update this list when creating a new object. This list will always be fresh, no request is required. Besides indexes, it also speeds up your application. The larger the result, the more reliable it can be managed, the more queries you can avoid.

2; Hide latency by β€œimproving” query results with recently added objects. Depending on the speed with which you add objects, either enter only the most recent key, or combine this with a solution of 1 .

3; Hide the delay by taking the user through some unaffected views before landing on your request based on the request. This strategy definitely smells above him. You need to make sure that these additional steps are relevant to the user, or you will get a bad experience.

Butterflies, Joachim

You can read it all here:

How will it turn out If I do not use async api after I delete the object, I still get it in the request, which is executed immediately after the removal or does not get it right after adding one


Another good answer to a similar question : Objectify does not save synchronously, even now

+7
source share

All Articles