【问题标题】:Datastore - Java class having its own typeDatastore - 具有自己的类型的 Java 类
【发布时间】:2014-11-13 17:15:29
【问题描述】:

我想创建一个类类型,它具有 n 个相同类型的子级和一个相同类型的父级作为成员。每个子类将有 n 个子级和一个父级。如果我将此模型保存在数据存储中,是否会耗费大量资源?因为每个孩子都有 n 个孩子等等。

说,

@PersistenceCapable
public class Human {

    @Persistent
    List<Human> children;

    @Persistent
    Human parent;

    //the getters and setters
    //null checks
    //add child to list
    //add parent
}

public class Test {
    public static void main(String[] args){
    Human parentHuman = new Human();
    Human childHuman = new Human();

    parentHuman.addChild(childHuman);
    childHuman.addParent(parentHuman);

    Human newChildHuman = new Human();
    newChildHuman.addParent(childHuman);
    newChildHuman.addChild(//another child);
    }
}

我还必须能够获得一个人类对象在任何时间点拥有的孩子的数量,以及他们孩子的孩子的数量。

那么,将这种类型存储在 Datastore 中会为每个孩子创建新实体,还是会引用人类对象的实体并重用它?

如果我的问题没有足够的解释性,我可以在我的问题中更清楚地说明问题。任何帮助/建议将不胜感激。谢谢

【问题讨论】:

  • 你在使用什么库(JDO、Objectify、低级 API)?

标签: java google-app-engine google-cloud-datastore


【解决方案1】:

一般来说,答案是否定的,只要您使用 keys 来建立实体之间的关系,就可以避免不必要的内联重复。始终使用实体关系的键。 For JDO, the specifics can be found here.

【讨论】:

  • 谢谢。我想通了。
猜你喜欢
  • 2016-10-26
  • 2021-01-25
  • 2015-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
  • 1970-01-01
相关资源
最近更新 更多