Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Configuring Private or Independent Relationships

In TopLink, object relationships can be either private or independent.

- In a private relationship, the target object is a private component of the source object. The target object cannot exist without the source and is accessible only through the source object. Destroying the source object will also destroy the target object.

- In an independent relationship, the source and target objects are public ones that exist independently. Destroying one object does not necessarily imply the destruction of the other.

Tip: TopLink automatically manages private relationships. Whenever an object is written to the database, any private objects it owns are also written to the database. When an object is removed from the database, any private objects it owns are also removed. Be aware of this when creating new systems, since it may affect both the behavior and the performance of your application.

Table 35-8 summarizes which mappings support this option.

Table 35-8 Mapping Support for Private or Independent Relationships

Mapping | Implicitly Private | Private or Independent | Using TopLink Workbench | Using Java
--- | --- | --- | --- | ---
Relational Mappings |  |  |  |
One-to-One Mapping |  |  |  |
Variable One-to-One Mapping |  |  |  |
One-to-Many Mapping |  |  |  |
Many-to-Many Mapping |  |  |  |
Aggregate Collection Mapping |  |  |  |
Direct Collection Mapping |  |  |  |
Direct Map Mapping |  |  |  |
Aggregate Object Mapping |  |  |  |
Object-Relational Mappings |  |  |  |
Object-Relational Structure Mapping |  |  |  |
Object-Relational Reference Mapping |  |  |  |
Object-Relational Array Mapping |  |  |  |
Object-Relational Object Array Mapping |  |  |  |
Object-Relational Nested Table Mapping |  |  |  |
EIS Mappings |  |  |  |
EIS Composite Direct Collection Mapping |  |  |  |
EIS Composite Object Mapping |  |  |  |
EIS Composite Collection Mapping |  |  |  |
EIS One-to-One Mapping |  |  |  |
EIS One-to-Many Mapping |  |  |  |
XML Mappings |  |  |  |
XML Composite Direct Collection Mapping |  |  |  |
XML Composite Object Mapping |  |  |  |
XML Composite Collection Mapping |  |  |  |

## Using TopLink Workbench

To create a privately owned mapping, use this procedure:

1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.

2. Click the General tab. The General tab appears.

   Figure 35-8 General tab, Private Owned option

   Description of "Figure 35-8 General tab, Private Owned option"

To create private ownership, select the Private Owned option.

## Using Java

For mappings not supported in TopLink Workbench, use the `independentRelationship``` (default), `privateOwnedRelationship```, and `setIsPrivateOwned``` methods.

Example 35-9 shows how to use these methods with a class that has a privately owned attribute, `phones`, in a mapping.

Example 35-10 Configuring Access Method in Java

    // Map the phones attribute
    phonesMapping.setAttributeName("phones");

    // Specify as privately owned
    phonesMapping.privateOwnedRelationship();