0
Sponsored Links


Ad by Google
Hibernate supports three basic inheritance mapping strategies, and each strategies has different way of implementations. Below are the three inheritance mapping strategies supported by Hibernate.
  1. table per class hierarchy
  2. table per concrete class
  3. table per sub class

Table per class hierarchy: Exactly one table is required, limitation columns declared by sub class cannot have not null constraints.

Syntax: <discriminator> column with <sub class="name" discrimination-value="value">


Example:
Using annotation
Using xml

Table per concrete class: Each table defines columns for all the properties of super class. Number of sub class is equals to number of tables required(two sub class required two tables).

Limitation: The identity generator strategy is not allowed. If property is mapped on the super class, then column name must be same on all sub class table.

Syntax: <union-subclass>

Example:
Using annotation
Using xml

Table per sub class: Foreign key is maintained between tables so superclass and subclass association is mapped with one to one association.
Limitation: Required tables is equals to number of classes including super class, caused one or more join operations to be performed to instantiate instance of sub class.

Syntax: <joined-subclass>  with <key> column

Example:
Using annotation
Using xml



References:
Reference 1
Reference 2
Reference 3


Done :)



Sponsored Links

0 comments:

Post a Comment