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.


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.

  1. Table per class hierarchy
  2. Table per subclass
  3. Table per concrete class
In the next article we will discuss all these mappings in details.



comments powered by Disqus