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. I read the relevant paragraph in the documentation, even tried it with JDO with @Element(dependent = “false”) but the problem remains. 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. 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.