Table per Hierarchy using Annotations (Single Table)

Table per Hierarchy using Annotations (Single Table)
We have already seen an example for Table per hierarchy (here). In this article we are going to see how Table per Hierarchy can be implemented in Hibernate using Annotations.


In this diagram, Employee is a class and Mobile and LandLine classes extends employee class. When we insert the values in them and when we run, all the data will be accumulated in a Single table. This is known as Table per Hierarchy.

Lets see this example in Detail,





From the output we can see that, we have used @Entity annotation in both mobile and landline classes but hibernate has created only one table Annotate_Employee and has inserted both the values of mobile and landline in single table


There is one column – DTYPE that differentiates the classes and the data





One thought to “Table per Hierarchy using Annotations (Single Table)”

Leave a Reply

Your email address will not be published. Required fields are marked *