Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Working with Nested Table Mappings

Nested table types model an unordered set of elements. These elements may be built-in or user-defined types. You can view a nested table as a single-column table or, if the nested table is an object type, as a muticolumn table (with a column for each attribute of the object type).

Typically, nested tables represent a one-to-many or many-to-many relationship of references to another independent structure. They support querying and joining better than Varrays that are inlined to the parent table.

OracleAS TopLink supports nested table through the NestedTableMapping class. They represent a collection of object references in Java, similar to a OneToManyMapping or ManyToManyMapping. However, the nested table mapping does not require foreign key information (as with a one-to-many mapping) or the relational table (as with a many-to-many mapping).

Implementing Nested Table Mappings in Java

Nested table mappings are instances of the NestedTableMapping class. This mapping is associated to an attribute in the parent class. The following elements are required for a nested table mapping to be viable:

  • The attribute being mapped, which is set by sending the setAttributeName() message

  • The field being mapped, which is set by sending the setFieldName() message

  • The name of the array structure, which is set by sending the setStructureName() message

Use the optional setGetMethodName() and setSetMethodName() messages to allow OracleAS TopLink to access the attribute through user-defined methods, rather than directly. See "Specifying Direct Access and Method Access" on page 4-71 for more information.

Table 7–5 summarizes all nested table mapping properties.

Example 7-5 Nested Table

The following code example illustrates creating a nested table mapping for the Insurance source class and registering it with the descriptor.

// Create a new mapping and register it with the source descriptor.
NestedTableMapping policiesMapping = new NestedTableMapping();
policiesMapping.setAttributeName("policies");
policiesMapping.setGetMethodName("getPolicies");
policiesMapping.setSetMethodName("setPolicies");
policiesMapping.setReferenceClass(Policy.class);
policiesMapping.dontUseIndirection();
policiesMapping.setStructureName("POLICIES_TYPE");
policiesMapping.setFieldName("POLICIES");
policiesMapping.privateOwnedRelationship();
policiesMapping.setSelectionSQLString("select p.* from policyHolders ph, table(ph.policies) t, policies p where ph.ssn=#SSN and ref(p) = value(t)");
descriptor.addMapping(policiesMapping);

Reference

The following table summarizes all nested table mapping properties. In the Method Names column, arguments are bold, methods are not.

Table 7-5 Properties for NestedTableMapping Methods

Property Default Method Names

* Required property




Attribute to be mapped * not applicable setAttributeName(String name)
Set parent class * not applicable setReferenceClass(Class referenceClass)
User-defined data type * not applicable setStructureName(String structureName)
Field to be mapped * not applicable setFieldName(String fieldName)
Method access direct access setGetMethodName(String name)

setSetMethodName(String name)

Indirection use indirection useIndirection()

dontUseIndirection()

setUsesIndirection(boolean usesIndirection)

Privately owned relationship independent independentRelationship()

privateOwnedRelationship()

setIsPrivateOwned(Boolean isPrivateOwned)

Read only read / write readWrite()

readOnly()

setIsReadOnly(boolean readOnly)