Skip Headers

# Implementing an Aggregate Object Relationship Mapping

Previous

Next

You must ensure that the following takes place:

- The descriptor of the target class declares itself to be an aggregate object. Because all its information comes from its parent's table(s), the target descriptor does not have a specific table associated with it. You must, however, choose one or more candidate table(s) from which you can use fields in mapping the target.

  In the example above, you could choose the `EMPLOYEE` table so that the `START_DATE` and `END_DATE` fields are available during mapping.

- The descriptor of the source class adds an aggregate object mapping that specifies the target class.

  In the example above, the `Employee` class has an attribute called `employPeriod` that would be mapped as an aggregate object mapping with `Period` as the reference class.

  The source class must ensure that its table has fields that correspond to the field names registered with the target class.

- If a source object has a `null` target reference, TopLink writes NULLs to the aggregate database fields (see "Configuring Allowing Null Values"). When the source is read from the database, it can handle this `null` target in one of two ways:

  - Create an instance of the object with all its attributes equal to `null`.

  - Put a `null` reference in the source object without instantiating a target. (This is the default method of handling `null` targets.)