简体   繁体   English

AppEngine:将孤儿保留在拥有的双向一对多关系中

[英]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.

相关问题 Gae Jdo坚持一对多拥有双向导航的关系 - Gae Jdo persistance on one-to-many owned relationship with bidirectional navigation 在JDO中使用一对多拥有的关系-AppEngine - Using one-to-many owned relationship in JDO - AppEngine 在一对多关系中替换父母后删除孤儿 - Removing orphans after replacing parent in a one-to-many relationship 拥有的一对多关系与拥有的一对多双向关系之间的区别(Google App Engine Java Api) - Difference between owned one to many relationship and owned one to many bidirectional relationship(Google App Engine Java Api) com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException,同时实现一对多双向关系App Engine - com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException while implementing One-To-Many bidirectional relationship App Engine 一对多关系 - Owned One-to-Many Relationships 为什么我拥有的一对多关系无法持久保存到GAE数据存储中? - Why doesn't my owned one-to-many relationship get persisted to the GAE datastore? GAE / J低层数据存储区API和DataNucleus JDO之间拥有的一对多关系的区别 - difference of owned one-to-many relationship between GAE/J low level datastore API and DataNucleus JDO 在Google Appengine中查询一对多模型 - Querying one-to-many model in Google appengine ndb中的一对多关系 - One-to-Many relationship in ndb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM