Header Ads

  • Breaking Now

    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 subclass

    Example:
    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 unions
    In this scenario there will be 2 tables
    Tables: Car, UtilityVan, here in this case all common attributes will be duplicated.

    2. Table per class hierarchy
    Single Table can be mapped to a class hierarchy
    There 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 UtilityVan

    3. Table per subclass
    Simply there will be three tables representing Vehicle, Car and UtilityVan

    1 comment:

    1. Excellent description for a concept I've tried to understand for a long time, thanks!

      ReplyDelete

    Post Top Ad

    Post Bottom Ad