Javatpoint Logo
Javatpoint Logo

Hibernate Inheritance Mapping Tutorial

We can map the inheritance hierarchy classes with the table of the database. There are three inheritance mapping strategies defined in the hibernate:

  1. Table Per Hierarchy
  2. Table Per Concrete class
  3. Table Per Subclass

Table Per Hierarchy

In table per hierarchy mapping, single table is required to map the whole hierarchy, an extra column (known as discriminator column) is added to identify the class. But nullable values are stored in the table .

Table Per Hierarchy using xml file
Table Per Hierarchy using Annotation

Table Per Concrete class

In case of table per concrete class, tables are created as per class. But duplicate column is added in subclass tables.

Table Per Concrete class using xml file
Table Per Concrete class using Annotation

Table Per Subclass

In this strategy, tables are created as per class but related by foreign key. So there are no duplicate columns.

Table Per Subclass using xml file
Table Per Subclass using Annotation





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA