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.
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.
- Table per class hierarchy
- Table per subclass
- Table per concrete class