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.