6.2.1 inheritance ing: Use the inheritance ing of the Union-subclass Element

Source: Internet
Author: User

Union-subclass ingSimilar to joined-subclass ing, attributes added to subclass can also have non-null constraints-that is, the data of the parent class instance is stored in the parent table, the data of the subclass instance is stored in the subtable. Unlike joined-subclass, the data of the subclass instance is only stored in the subclass table, and there is no record in the parent table. In this ing policy, the fields in the subclass table are more than those in the parent table, because the fields in the subclass table are equal to the sum of the attributes added to the parent attribute and subclass.

Person. HBM. xml:

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">    

Using the Union-subclass ing policy is very concise. You do not need to use the discerning column or the key sub-element to map a common primary key column. You only need to use the Union-subclass ing subclass. This policy is easy to use, and Li Gang enjoys it.

Run personmanager. Java to view the database:

The limitation of this method is thatIf an attribute is mapped to a superclass, its field name must be the same as that defined in all subclass tables. In addition, the Union-subclass ing policy cannot be used to generate the policy using the identity primary key, because all entity classes in the same class hierarchy must use the same primary key seed (that is, the primary keys of records corresponding to multiple persistent entities are continuous ). This affects native primary key generation policies, because native selects the identity or sequence policy based on the database.

In this ing policy, different persistence instances are stored in different tables, and data is not required to be retrieved across multiple tables when loading the content of an instance. However, in this ing policy, multi-table queries also need to be performed across multiple tables. For example, to query a person instance that meets a certain condition, Hibernate queries data from the persons table and from the table corresponding to all child classes of person, then perform the union operation on the result data ------ this is why this ing policy is called Union-subclass.

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.