What are the inheritance strategies supported in Hibernate?

Answered

What are the inheritance strategies supported in Hibernate?

Ninja Asked on 18th September 2018 in Hibernate.
Add Comment
1 Answer(s)
Best answer

Three basic inheritance mapping strategies supported in Hibernate are:

1. Table per class hierarchy strategy: A single table hosts all the instances of a class hierarchy. This table would include columns for all properties of all classes in the hierarchy. A discriminator is used as a key to uniquely identify the base type of the class hierarchy. This mapping strategy is preferred because of its performance and simplicity.

2. Table per concrete class strategy: One table per concrete class and subclass is present and each table persist the properties of the class and its superclasses. The main problem with this strategy is that it doesn’t support polymorphic associations very well.

3. Table per subclass strategy: One table per class and every subclass is present including abstract classes. Unlike the strategy that uses a table per concrete class, the table here contains columns only for each non-inherited property (each property declared by the subclass itself) along with a primary key that is also a foreign key of the superclass table. Even though this mapping strategy is deceptively simple, the performance may be problem for complex class hierarchies.

Ninja Answered on 18th September 2018.
Add Comment