Example: Amazon Online shopping mall can sell a lot of things, such as books, electrical appliances, fruits, etc., Then we use object-oriented concept to abstract a commodity class, he has a common property of the commodity, such as the shelf time, the current price, preferential price waiting, The commodity can inherit the commodity class, can also retain their own properties, such as product name and so On. This relationship is called Inheritance.
As mentioned above, the inheritance is embodied in the database, and the inheritance is implemented in Hibernate.
The database table embodies the inheritance, you can first create a commodity class table, and then create a commodity table (type variable), They have the same primary key to establish contact.
Table Structure:
How to implement an inheritance relationship in hibernate, first create the parent class and subclass, then let the subclass inherit the parent class, and finally write the mapping File.
Step One: Writing entity classes
Step Two: Write the mapping file
The mapping file is written here, not the Subclass's configuration file, that is, the subclass does not write the configuration file, only need to write the parent Class's configuration file, and then the map of the class to load into it,
The parent Class's configuration file------------------------------------------------------------------------------------------------------------------ ----
How to add a configuration file for a subclass------------------------------------------------------------------------------------
Analysis: by <joined-subclass> loading subclasses, key common primary key--> connected bridge
Finally: If the user has more than a subclass, it can be loaded by the upstream tag subclass, to achieve the basic effect
The inheritance relationship of Hibernate table relationship Mapping