Reputation: 545
I'm using HRD because I want make changes to multiple entities within a single transaction using entity groups.
Understand that Non transactional (non ancestor) queries may see all, some, or none of the results of a previously committed transaction.
The problem I facing now is: After commit an transaction for adding new record to db
Transaction tx = pm.currentTransaction();
tx.begin();
pm.makePersistent(object);
tx.commit();
Follow by query the record committed, sometime it will return result and some time just return as null
Query q = pm.newQuery(queryStatement);
CompanyProfile result = (CompanyProfile) q.execute();
p/s: When turn off HRD, it work perfectly.
Any workaround?
Thanks Rgds SJ
Upvotes: 2
Views: 354
Reputation: 15143
If the following query is also done within the same transaction, it should return the proper result. However, all other queries are eventually consistent, that's unfortunately the nature of the datastore.
Upvotes: 0
Reputation: 3769
You might want to take a look at Google Cloud SQL if you want to use a relational database model: https://developers.google.com/cloud-sql/ I haven't tried it myself, but I don't use any transactions in my app.
I would definitely NOT use the old non-HR datastore. I wouldn't be surprised if it's gone by the end of the next year or two. It's not anywhere near as reliable as HR datastore. But as you discovered, eventual consistency can be tricky if you're not used to it.
Upvotes: 0
Reputation: 80340
There is no way around it: HRD is always eventually consistent: http://code.google.com/appengine/docs/python/datastore/queries.html#Setting_the_Read_Policy_and_Datastore_Call_Deadline
One way around it would be to use get instead of query. Get/put/delete are strongly consistent in HRD, while query is eventually consistent: http://code.google.com/appengine/docs/java/datastore/hr/
If this is a immediate-query-after-save scenario within one user session, you could query data and add a saved entity to the list by hand.
Upvotes: 1