3.7.4.2.1. Dependent
In a dependent relation, the referenced object is deleted whenever the owning object is deleted, or whenever the relation is severed by nulling or resetting the owning field.
For example, if the
Magazine.coverArticle field is marked dependent, then setting Magazine.coverArticle to a new Article instance will automatically delete the old Article stored in the field.
Similarly, deleting a Magazine object will automatically delete its current cover Article.
(This latter processing is analogous to using JPA’s CascadeType.REMOVE functionality as described in Cascade Type.) You can prevent an orphaned dependent object from being automatically deleted by assigning it to another relation in the same transaction.
OpenJPA offers a family of marker annotations to denote dependent relations in JPA entities:
-
org.apache.openjpa.persistence.Dependent: Marks a direct relation as dependent.
-
org.apache.openjpa.persistence.ElementDependent : Marks the entity elements of a collection, array, or map field as dependent.
-
org.apache.openjpa.persistence.KeyDependent: Marks the key entities in a map field as dependent.