aiszatt
aiszatt

Reputation: 21

Datastore entity properties not returning

So I store a "User" entity in the Datastore, which is visible in the Datastore Viewer and I can see all properties that I expect, which includes a property called contacts that contains a list of type long (representing IDs of people in that user's contact list). This is stored using userEntity.setProperty("contacts", ids); where ids is a List<Long>.

However, when I use Java on App Engine to extract this entity (without any projections, just a filter on the email address of the user I'm looking for) I receive an entity object that doesn't have the contacts property.

Is there any reason why I wouldn't be receiving the full set of properties? The code I'm using is (hopefully) relatively standard:

Query.Filter emailFilter = new Query.FilterPredicate("email", Query.FilterOperator.EQUAL, email);
Query q = new Query("User").setFilter(emailFilter);
Entity userEntity = datastoreService.prepare(q).asSingleEntity();
logger.info(userEntity.toString());

This outputs:

<Entity [User(5156288090603520)]:
lastName = Doe
updatedTs = 1414005061759
email = [email protected]
firstName = John
ownerEmail = [email protected]
>

Which is everything I see in the viewer except the contacts property that contains the list. As such if I try userEntity.getProperty("contacts"); then I get a null object. If I run a GQL query in App Engine Console:

SELECT contacts FROM User

I also get the expected result. Any idea why my Java query doesn't return this property?

Upvotes: 2

Views: 1042

Answers (1)

Nick
Nick

Reputation: 3591

In regards to what @Patrick Costello is posting in the comments, I'd add that yeah, eventual consistency is the cause of this, but you can also attempt to alleviate these side effects of eventual consistency by adding entities to entity groups using ancestors. From this link:

To obtain strongly consistent query results, you need to use an ancestor query limiting the results to a single entity group. This works because entity groups are a unit of consistency as well as transactionality.

Upvotes: 0

Related Questions