英文:
Google datastore delete entity does not immediately update, can access in next line with find()
问题
我遇到一个问题,即当删除实体后,数据存储表不会立即更新,并且可以使用DB.find来访问。
以下是流程:
- DB.find(key) --> 对象
- DB.delete(object)
- DB.find(key) --> 对象(非空)
我期望DB.find(key)返回null,因为对象未被删除,但事实并非如此。然而,当所有逻辑完成并且响应已经返回后,我看到实体已经成功删除。
为什么实体仍然可以在同一个函数内找到?
此外,每个DB访问步骤都使用ObjectifyService事务包装,例如:
Boolean txnRes = ObjectifyService.ofy().transact(new Boolean() {
@Override
public Boolean run() {
object = DB.find(key)
return object != null
}
});
英文:
I am running into an issue where the datastore table does not immediately update when an entity is deleted, and can be accessed with DB.find.
Here is the flow:
1. DB.find(key) --> object
2. DB.delete(object)
3. DB.find(key) --> object (not null)
I expect DB.find(key) to return null because the object was not deleted but that is not the case. However, after all logic completes and response has been returned I see that the entity has been successfully deleted.
Why is the entity still able to be found within the same function?
Also, each of the DB access steps are wrapped with ObjectifyService transaction, for example:
Boolean txnRes = ObjectifyService.ofy().transact(new Boolean() {
@Override
public Boolean run() {
object = DB.find(key)
return object != null
}
});
答案1
得分: 1
根据此帖子上@Dan Cornilescu的回答,您必须在实体的键上调用.delete()
,而不是在实体本身上。即
DB.key.delete()
还请查看此文档。
英文:
As per the answer by @Dan Cornilescu on this thread. you have to call .delete()
on the entity's key, instead of entity itself. I.e
DB.key.delete()
Also check this document
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论