[英]AppEngine: Retaining orphans in an owned, bidirectional one-to-many relationship
I have the following two entities: 我有以下两个实体:
@Entity
public class SupermarketChain {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;
@OneToMany(mappedBy = "supermarketChain")
@Basic
private List<Supermarket> supermarkets;
}
@Entity
public class Supermarket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;
@ManyToOne(optional=true)
private SupermarketChain supermarketChain;
}
When I'm deleting a parent with em.remove(SupermarketChain.class, key), all orphans will be deleted too. 当我使用em.remove(SupermarketChain.class,key)删除父母时,所有孤儿也将被删除。 I read the relevant paragraph in the documentation, even tried it with JDO with @Element(dependent = "false") but the problem remains.
我阅读了文档中的相关段落 ,甚至在JDO中使用@Element(dependent =“ false”)进行了尝试,但问题仍然存在。 How can I retain the orphans in that relation?
我该如何保留这些孤儿呢?
Retaining an orphan makes no sense. 保留一个孤儿毫无意义。 In v1 of GAE JDO/JPA all relations are "owned" so you have to have a parent of any child.
在GAE JDO / JPA v1中,所有关系都是“所有者”,因此您必须有任何孩子的父母。 And if the parent no longer exists then the child is deleted.
如果父级不存在,则删除子级。 Always.
总是。
In v2 of GAE JDO/JPA you will also be able to have unowned objects, hence there is no "parent" and so they can continue to exist after. 在GAE JDO / JPA第2版中,您还可以拥有未拥有的对象,因此没有“父”对象,因此它们之后可以继续存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.