Search This Blog

Thursday, April 17, 2008

Explain different inheritance mapping models in Hibernate?

There can be three kinds of inheritance mapping in hibernate

1. Table per concrete class with unions

2. Table per class hierarchy

3. Table per subclassExample:

We can take an example of three Java classes like Vehicle, which is an abstract class and two subclasses of Vehicle as Car and UtilityVan.1. Table per concrete class with unionsIn this scenario there will be 2 tablesTables: Car, UtilityVan, here in this case all common attributes will be duplicated.2. Table per class hierarchySingle Table can be mapped to a class hierarchyThere will be only one table in database named 'Vehicle' which will represent all attributes required for all three classes.Here it is be taken care of that discriminating columns to differentiate between Car and UtilityVan3. Table per subclassSimply there will be three tables representing Vehicle, Car and UtilityVan

No comments: