我现在正在写这篇文章,如果我错了,请纠正我。但我想要记住,以下代码验证Ref<>背后的实体是否存在。实际存在:
Ref<User> user; // we have a reference field to a user in another entity
public void referenceUser(Long userId) {
Key<User> key = Key.create(User.class, userId); // this is protobuf as it looks, and no db access happens
this.user = Ref.create(key); // this looks up if an existing record exists, and it fails if it does not, correct?
}
如果Ref&lt;&gt;会发生什么?更新期间是否已设置字段?如果记录仍然存在,是否再次验证是否正确?
我想澄清objectify何时确保数据完整性以及何时不反复检查引用记录是否存在。
答案 0 :(得分:1)
Objectify永远不会确保任何形式的参照完整性。也没有低级API。
Ref对象只是具有更多行为的Key对象(最重要的是get()方法)。