WebObjects/EOF/Modeling/Inheritance

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.

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: Sellables

pk

name

cost

objType

1

Corvette

50000

1

2

Volkswagen

10000

1

3

Piper Cub

50000

2

4

Lear Jet

100000

2

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.