【发布时间】:2013-04-04 14:46:20
【问题描述】:
我有两个实体parent 和child,它们有一个OneToMany relationship。父类有一个@Owned 子类的注解。后面没有关系。 (从孩子到父母)
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Owned
@OneToMany(fetch = FetchType.LAZY)
private Set<Child> children;
.........
}
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key id;
public String value;
.........
public int hashCode() {
... based on this.value ...
}
public boolean equals(Object o) {
... based on this.value ...
}
}
问题 1: 此设置是否类似于以 Parent 为祖先的实体组?以下两个语句确实返回一个相等的 Key:
- child.getId().qv.getId().getParent()
- KeyFactory.createKey("Parent", parent.getId())
问题 2: 下面的代码是否需要大约十秒的时间来执行?它的运行时间约为 223 毫秒:
for(int i = 0; i < 10; i++) {
em.getTransaction().begin();
parent = em.find(Parent.class, parentId);
child = new Child("value" + i);
parent.addChild(child)
em.merge(parent)
em.getTransaction().commit();
}
我认为应该需要 10 秒的原因是因为 Google App Engine 文档中的这句话:
“但是,您可以写入同一实体组的速率限制为每秒 1 次写入实体组。”
在https://developers.google.com/appengine/docs/java/gettingstarted/usingdatastore
谢谢
【问题讨论】:
标签: java google-app-engine jpa