Home » Hibernate » Inheritance Mapping In Hibernate

Inheritance Mapping In Hibernate

Java is object oriented language and inheritance is one of main functionalities of java.Relation model can implement "is a" and "has a" relationship but hibernate provides us way to implement class hierarchy in a different ways.

When developing the hibernate applications, it may have multiple pojo classes. And the pojo classes may have same common properties also. If there are common properties then in order to get re-usability, we can create a super class for the common properties. And we extend the sub class from that super class.

In this mapping if we have base and derived classes, now if we save derived(sub) class object, base class object will also be stored into the database.

For example:

class Vehicle 
{
   // code will goes here
}

class Car extends Vehicle 
{
   // code will goes here
}

If you save Car class object, then Vehicle class object will also be saved into the database

There are 3 ways in which you can implement inheritance in hibernate.

  • Table per class hierarchy
  • Table per subclass
  • Table per concrete class

In the next article we will discuss all these mappings in details.

Previous Next Article

comments powered by Disqus