1.

Can you explain the concept behind Hibernate Inheritance Mapping?

Answer»

Java is an Object-Oriented Programming Language and INHERITANCE is one of the most important pillars of object-oriented principles. To represent any models in Java, inheritance is most commonly used to simplify and simplify the relationship. But, there is a catch. Relational databases do not SUPPORT inheritance. They have a flat structure.

Hibernate’s Inheritance Mapping strategies deal with solving how to hibernate being an ORM tries to map this problem between the inheritance of Java and flat structure of Databases.

Consider the example where we have to divide InterviewBitEmployee into CONTRACT and Permanent Employees represented by IBContractEmployee and IBPermanentEmployee classes respectively. Now the task of hibernate is to represent these 2 employee types by CONSIDERING the below restrictions:

The general employee details are defined in the parent InterviewBitEmployee class. 

Contract and Permanent employee-specific details are stored in IBContractEmployee and IBPermanentEmployee classes respectively

The class diagram of this system is as shown below:

Hibernate’s Inheritance Mapping

 

There are different inheritance mapping strategies available:

  • Single Table STRATEGY
  • Table Per Class Strategy
  • Mapped Super Class Strategy
  • Joined Table Strategy


Discussion

No Comment Found