The inheritance relationship of Hibernate table relationship Mapping

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.