Hibernate Inheritance – Table Per Concrete Class Hierarchy Example(XML Mapping & Annotation)

Table per Class Hierarchy strategy will be having a single table for both the Parent class and the Sub class separated by a discriminator column. In Table per Subclass Hierarchy, subclass table will be mapped to the Parent class table by primary key and foreign key relationship. In Table Per Concrete Class Hierarchy also individual table will be created for each class. The disadvantage of this approach is that all the columns of the Primary class table will be again replicated in the Subclass table.

[Read more…]

Hibernate Inheritance – Table Per Class Hierarchy (XML Mapping & Annotation)

Java being an Object Oriented Language, it supports one of the most powerful concept “Inheritance“. Object Oriented Systems generally supports both IS-A and HAS-A relationships, whereas Relational Model supports only HAS-A relationship. Hibernate can help you map such kind of entities into the Relational table based on the strategy selected.

Types of Inheritance in Hibernate

Hibernate offers 3 different approaches for mapping this kind of hierarchical classes.

  1. Table per Class hierarchy
  2. Table per Sub-Class hierarchy
  3. Table per Concrete Class hierarchy

[Read more…]

Hibernate One-to-One Bidirectional Mapping Example – Foreign Key(Annotation)

In this article, we will learn how to achieve Hibernate One-to-One Bidirectional Mapping using the JPA Annotations with Foreign Key, in the previous One-To-One Bidirectional Mapping Example we used only the Primary Key. This Annotation approach is just an alternative to the XML mapping which we used in our earlier article Hibernate One-To-One Mapping XML Example with Foreign Key
[Read more…]