views:

72

answers:

1

I am using JOINED inheritance strategy with EclipseLink JPA implementation. I have noticed that EclipseLink is adding discriminator column, named by default DTYPE, to the database schema. I understand, that discriminator is needed for one table inheritance strategy, but why for JOINED strategy?

EclipseLink needs this column because I've got errors after removing it. Is this column added for performance reasons, etc? I am not particularly happy about that since from the point of view of database schema this column is just unnecessary clutter.

Hibernate based JPA does not do anything similar.

A: 

From Joined Table Inheritance:

In the joined table inheritance, each class shares data from the root table. In addition, each subclass defines its own table that adds its extended state. The following example shows two tables, PROJECT and L_PROJECT, as well as two classes, Project and LargeProject:

...

The discriminator column is what determines the type and thus what joined table to use so you need a discriminator column in the parent table.

cletus
Exactly, and this is what I want to understand: why EclipseLink is using this discriminator column - it is not necessary, JOINED strategy is based on foreign keys association between classes.The JPA spec says that discriminator is optional for JOINED strategy - Hibernate JPA is not using it for instance - and I would like to learn what is the advantage of using it, as EclipseLink does.
Piotr Kochański
I guess you're referring to http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tablepersubclass. ExlipseLink I guess is just explicit in this regard. The discriminator column avoids the problem of doing EXISTS (or similar) checks to find the appropriate subclass. Even if it were optional I'd still use it.
cletus
That makes sense, discriminator surely makes things easier to implement. Thanks for you answer!
Piotr Kochański