ObjectExtender User's Guide and Reference

Creating single table inheritance maps

A single table inheritance map is used to map two or more persistent model classes to the same table. This is useful for persistent objects that have basically the same data but different behaviors. An example of this type of mapping is included with the Bank sample model.

Launch the Map Browser, and select BankSample from the Datastore Maps view, and then select VapAccount from the Persistent Classes view.

Note that VapAccount has two subclasses: VapCheckingAccount and VapSavingsAccount. All three of these classes map to the ACCOUNT table.

It was created as follows:

  1. Select VapAccount from the Persistent Classes view.
  2. From the Table_Maps menu, select New Table Map - Add Single Table Inheritance Table Map.


    Figure pgs2l not displayed.

  3. Select ACCOUNT for the Table.
  4. Type: $A for the Discriminator value.
  5. Select OK.
  6. Select VapCheckingAccount from the Persistent Classes view.
  7. From the Table_Maps menu, select New Table Map - Add Single Table Inheritance Table Map.
  8. Select ACCOUNT for the Table.
  9. Type: C for the Discriminator value.
  10. Select OK.
  11. Select VapSavingsAccount from the Persistent Classes view.
  12. From the Table_Maps menu, select New Table Map - Add Single Table Inheritance Table Map.
  13. Select ACCOUNT for the Table.
  14. Select TYPE for the Discriminator column.
  15. Type: S for the Discriminator value.
  16. Select OK.

The single table inheritance mapping is now defined.

For a model that has inheritance, when a new schema is generated a single table inheritance approach is used. However, the table maps for the primary table is created once but added twice to each class map. To correct this, select one of the table maps and select the option in the browser to delete it.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]