Based on the Q&A from here: Get an Objectify Entity s Key
对于持续对象,获得实体的钥匙如下:
@Transient
Key<Categoria> getKey() {
return new Key<Categoria>(Categoria.class, id);
}
Doenn t 返回相同的密钥 :
Objectify ofy = ObjectifyService.begin();
Key<Categoria> key = ofy.getFactory().getKey(someobject);
还是应该?
我的模特看起来是这样的:
@Entity
class Categoria{
@Parent
private Key<Someclass> parentKey;
@Transient
Key<Categoria> getKey() {
return new Key<Categoria>(Categoria.class, id);
}
// Code omitted
}