Java 如何在JDO中唯一地标识和获取子对象
我只是在学习JDO和GAE,我已经在这个问题上陷入了困境 我已经从刚才的Java 如何在JDO中唯一地标识和获取子对象,java,google-app-engine,jdo,Java,Google App Engine,Jdo,我只是在学习JDO和GAE,我已经在这个问题上陷入了困境 我已经从刚才的 public class Article { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; ... } 到现在,也有了父母: public class ArticleCollection { @PrimaryKey @Persistent(valu
public class Article {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
...
}
到现在,也有了父母:
public class ArticleCollection {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
private long count
private Set<Article> articles;
}
非常感谢任何帮助 子项的键包含有关其父项的信息。您需要使用包含父ID的KeyFactory方法
createKey(Key parent, java.lang.String kind, long id)
Creates a new Key with the provided parent from its kind and ID.
有关更多详细信息,请查看。为了方便起见,还提供了一个生成器类,允许您执行以下操作:
Key key = new Builder("ArticleCollection", 123).addChild("Article", 1424).getKey();
随着层次结构的加深,该表单变得更加有用,因为您可以在调用getKey
之前将一堆addChild
链接在一起
如果您不知道一篇文章的父级,我认为您只能执行GQL查询,而不能执行get by键
Key key = new Builder("ArticleCollection", 123).addChild("Article", 1424).getKey();