ObjectExtender User's Guide and Reference

Creating root/leaf inheritance maps

A root/leaf inheritance map is similar to the single table inheritance map, except that each subclass may have additional information to the superclass and this information will be stored in a separate table. When the subclass is instantiated, it will obtain its information from its table as well as from the superclasses' table. An example of this type of mapping can be found in the AutoWorld example.

Launch the Model Browser and select AutoWorld from the Models view. Double-click on VapVehicle to expand its hierarchy.

Below is a diagram of the class hierarchy for VapVehicle in the Model Browser.


Figure pgs2m not displayed.

If you open the Schema Browser and select AutoWorld, you will notice that there is a separate table for each of the model objects in the VapVehicle class hierarchy (VEHICLE, BUS, AUTOMOBILE, RACECAR).

Each of the leaf tables (AUTOMOBILE, RACECAR, and so on) have foreign key relationships to their parent table. The important part of this example is how the models from the Model Browser are mapped to the tables in the Schema Browser. This can seen in the Map Browser.

  1. Launch the Map Browser.
  2. Select AutoWorld from the Datastore Maps view.
  3. Select VapVehicle from the Persistent Classes. Double-click on this class to expand its hierarchy.
  4. From the Table_Maps menu, select New Table Map - Add Root/Leaf Inheritance Table Map.

    This opens the Root Leaf Inheritance Map editor.


    Figure pgs2n not displayed.

  5. Select VEHICLE for the Table.
  6. Select VEHICLE_TYPE for Discriminator column.

    Note that a discriminator value is not entered for the VEHICLE table because the VapVehicle is only an abstract class and cannot be instantiated. If, in your application, the root of the model hierarchy can be instantiated, you must enter the discriminator value.

  7. Ensure that the Root of the model hierarchy is selected.
  8. Select OK.
  9. Select VapAutomobile from the Persistent Classes view.
  10. From the Table_Maps menu, select New Table Map - Add Root/Leaf Inheritance Table Map.


    Figure pgs2o not displayed.

  11. Select AUTOMOBILE for the Table.
  12. Type Automobile for the Discriminator value.
  13. Type automobile to vehicle for the Foreign Key Relationship.
  14. Select OK.
  15. Select VapRaceCar from the Persistent Classes view.
  16. From the Table_Maps menu, select New Table Map - Add Root/Leaf Inheritance Table Map.

    This opens the Root Leaf Inheritance Map editor.


    Figure pgs2p not displayed.

  17. Select RACECAR from the Table list.
  18. Type RaceCar for the Discriminator value.
  19. Select racecar to automobile from the Foreign Key Relationship menu.
  20. Select OK.
  21. Select VapBus from the Persistent Classes view.
  22. From the Table_Maps menu, select New Table Map - Add Root/Leaf Inheritance Table Map.

    This opens the Root Leaf Inheritance Map editor.


    Figure pgs2q not displayed.

  23. Select BUS from the Table list.
  24. Type Bus for the Discriminator value.
  25. Select bus to vehicle from the Foreign Key Relationship menu.
  26. Select OK.

The root/leaf inheritance table map is now defined.


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