Sponsored Links
Ad by Google
Well, we all know hibernate supports three basic inheritance strategy, while giving interview most of the time interviewer asked you about inheritance in hibernate. Once you started fruitful discussion on inheritance strategies. Interviewer asked you about the differences between all the inheritance strategies and most popular differences asked in hibernate interview is Difference between Table-Per-Subclass and Table-Per-Concrete class. Below are the few differences.
Here is an example of Table-Per-Sub-Class using annotation and Table-Per-Concrete-Class using annotation
References:
Reference 1
Reference 2
Reference 3
- In Table Per Subclass inheritance, number of tables should be exactly equals to number of classes including superclass. For example if you have three subclass and one superclass in your inheritance hierarchy then total number of table required 1(superclass)+3(subclass) = 4. Whereas In Table-Per-Concrete class, number of tables exactly equals to number of subclasses. For example if you have three subclass and one superclass in your inheritance hierarchy then total number of table required 3 only.
- In Table-Per-Subclass,
element is used with attribute in hbm.xml and InheritanceType.JOINED(in superclass) with @PrimaryKeyJoinColumn(in subclass) is used in annotation version. Whereas In Table-Per-Concrete class, element is used in hbm.xml and InheritanceType.TABLE_PER_CLASS(in superclass) with @AttributeOverrides(in subclass) is used in annotation version.
In Table-Per-Subclass, identity generator strategy is allowed. But in Table-Per-Concrete class identity generator strategy is not allowed.
In Table-Per-Subclass, foreign key is maintained between tables so superclass and subclass association is mapped with one to one association no needs to overrides the properties of superclass. Whereas In Table-Per-Concrete class, no foreign key maintained between tables, so each table defines columns for all properties of the class, including inherited properties.
Here is an example of Table-Per-Sub-Class using annotation and Table-Per-Concrete-Class using annotation
References:
Reference 1
Reference 2
Reference 3
Sponsored Links
0 comments:
Post a Comment