Inheritance which is one of the pillars of Object Oriented Programming Model isn't a big player in the SQL environment. While Objects can form both IS-A and HAS-A relationships, Tables are only aware of HAS-A relationships. (for e.g. 1 Person has many Vehicles)
Hibernate provides techniques that allows us to represents Tables via inheritance relationships. Hibernate has 4 different approaches:
NOTE: Other sports lovers out there: I have used a very small sub set of attributes below to keep my Tables simple. Under no condition, is this to be considered as my very poor knowledge of these two really awesome sports :p
The java models for the above hierarchy would be as below:
Hibernate provides techniques that allows us to represents Tables via inheritance relationships. Hibernate has 4 different approaches:
- Table per Concrete Class + Implicit Polymorphism
- Table per Concrete Class + Unions
- Table per Class Hierarchy
- Table per subclass
NOTE: Other sports lovers out there: I have used a very small sub set of attributes below to keep my Tables simple. Under no condition, is this to be considered as my very poor knowledge of these two really awesome sports :p
public abstract class SportsPerson { private Long id; private String name; //setter getter }
public class Cricketer extends SportsPerson { private Integer runs, wickets; private Boolean t20Player; // setter getter for above properties }
public class Footballer extends SportsPerson { private Integer goals, appearances, sendOffs; // setter getter for above properties }I shall implement each of the supported approaches for this model schema in the coming posts
No comments:
Post a Comment