Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why EclipseLink is adding discriminator column for joined inheritance strategy?

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.

like image 909
Piotr Kochański Avatar asked Jan 14 '10 10:01

Piotr Kochański


People also ask

What is the use of discriminator column in hibernate?

In case of table per class hierarchy an discriminator column is added by the hibernate framework that specifies the type of the record. It is mainly used to distinguish the record. To specify this, discriminator subelement of class must be specified. The subclass subelement of class, specifies the subclass.

Is a mapping requires discriminator column?

The SINGLE_TABLE strategy maps records from the same database table to different entity classes of an inheritance hierarchy. If you want to use this strategy with JPA, your database table needs to have a discriminator column. The value in this column identifies the entity class to which each record shall be mapped.

What is discriminator in JPA?

The discriminator column is always in the table of the base entity. It holds a different value for records of each class, allowing the JPA runtime to determine what class of object each row represents. The DiscriminatorColumn annotation represents a discriminator column.

Which inheritance strategy creates a single table?

The single table strategy is one of the most simplest and efficient way to define the implementation of inheritance. In this approach, instances of the multiple entity classes are stored as attributes in a single table only.


1 Answers

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.

like image 169
cletus Avatar answered Jan 03 '23 00:01

cletus