Use @PrivateOwned
to specify that a relationship is privately owned; target object is a dependent part of the source object and is not referenced by any other object and cannot exist on its own.
Annotation Elements
The @PrivateOwned
annotation does not have attributes.
Usage
Using @PrivateOwned
causes many operations to be cascaded across the relationship including delete, insert, refresh, and lock (when cascaded). It also ensures that private objects removed from collections are deleted and that objects added are inserted.
You can specify @PrivateOwned
on with @OneToOne
, @OneToMany
and @VariableOneToOne
annotations. Private ownership is implied with the @BasicCollection
and @BasicMap
annotations.
When the referenced object is privately owned, the referenced child object cannot exist without the parent object.
Additional Information
When indicating that a relationship is privately owned, you are specifying the following:
If the source of a privately owned relationship is deleted, then EclipseLink will delete the target. This is equivalent of setting @CascadeOnDelete.
If you remove the reference to a target from a source, then EclipseLink will delete the target.
Normally, do not configure privately owned relationships on objects that might be shared. An object should not be the target in more than one relationship if it is the target in a privately owned relationship.
Referencing a privately owned object may produce undesired effects, as it is the application's responsibility to "clean up" references to the privately owned object. If the object becomes de-referenced and is deleted, other objects in the cache that continue to reference the deleted object may cause constraint violations, they may resurrect the object (if using cascade persist), or they may simply not reflect what is in the database. |
Examples
Example 2-93 shows using @PrivateOwned
to specify Employee
field phoneNumbers.
.
Example 2-93 Using @PrivateOwned Annotation
@Entity public class Employee implements Serializable { ... @OneToMany(cascade=ALL, mappedBy="employee") @PrivateOwned public Collection<PhoneNumber> getPhoneNumbers() { return phoneNumbers; } ... }
See Also
For more information, see: