Child pages
  • EOF-Modeling-Inheritance
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Entity inheritance is a way to take advantage of the object-relational mapping layer between the EOEntity objects and the table structure in the database to provide flexibility. This flexibility can also become a source of problems, so care must be taken when using this feature. There are many tricks available from the flexibility this feature provides.

There are three kinds of entity inheritance that represent different ways to map a table or tables to an entity or entities.

Single-Table Inheritance

In single-table inheritance, a single table can be used for more than one entity. The most sure way to do this is to use a column, or a set of columns, that have ordinal values.

An example would be:

<table border="1">
<caption>Table: Sellables</caption>
<tr><th>pk</th><th>name</th><th>cost</th><th>objType</th></tr>
<tr><td align="right">1</td><td align="right">Corvette</td><td align="right">50000</td><td align="right">1</td></tr>
<tr><td align="right">2</td><td align="right">Volkswagen</td><td align="right">10000</td><td align="right">1</td></tr>
<tr><td align="right">3</td><td align="right">Piper Cub</td><td align="right">50000</td><td align="right">2</td></tr>
<tr><td align="right">4</td><td align="right">Lear Jet</td><td align="right">100000</td><td align="right">2</td></tr>
</table>

One can create two entities. In one entity, called "Cars", the external name would be "Sellables" and there would be a restricting qualifier saying that "objType = 1". For another entity, called "Planes", the external name would also be "Sellables" and there would be a restricting qualifier saying that "objType = 2".

When instances of the Cars or the Planes entity are created, one must make sure to set the objType attribute. It is often simplest to have custom EO classes for the entities that can handle the initiation reliably.

Horizontal Inheritance

Vertical Inheritance

  • No labels