Senin, 12 Januari 2015

Inheritance Mapping in Hibernate Tutorial with examples

Compared to JDBC we have one main advantage in hibernate, which is hibernate inheritance.

Inheritance is one of the most visible facets of Object-relational mismatch. Object oriented systems can model both “is a” and “has a” relationship. Relational model supports only “has a” relationship between two entities. Hibernate can help you map such Objects with relational tables. But you need to choose certain mapping strategy based on your needs.

Inheritance Mapping Strategies in Hibernate

Hibernate supports 3 types of Inheritance Mappings:
  1. Table per class hierarchy
  2. Table per sub-class hierarchy
  3. Table per concrete class hierarchy
Note: We can also called this Hibernate Inheritance Mapping as Hibernate Hierarchy

Table Per Hierarchy

In table per hierarchy mapping, single table is required to map the whole hierarchy, an extra column (known as discriminator column) is added to identify the class. But nullable values are stored in the table .

Table Per Concrete class

In case of table per concrete class, tables are created as per class. But duplicate column is added in subclass tables.

Table Per Subclass

In this strategy, tables are created as per class but related by foreign key. So there are no duplicate columns.
Inheritance Mapping in Hibernate Tutorial with examples


Source:http://www.tutorialsdesk.com/2015/01/inheritance-mapping-in-hibernate.html

Tidak ada komentar:

Posting Komentar