Hibernate Federated Primary Key mapping rules:
First: Primary keys and attributes in a class
1. Configuration files
<?xml version= "1.0"?>
<! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en"
"http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd ">
Note: The primary key configuration label for the Federated primary Key is represented by <composite-id>. <key-property represents the primary key.
2.
2. Mapping rules for federated primary keys
Each primary key attribute in the class corresponds to each primary key column in the data table. Hibernate requires an entity class with a federated primary key to implement the serializable interface, and overrides the hashcode with the Equals method, because hibernate determines whether a two-row record is the same based on the Federated primary key of the database. If it is the same, then it is considered to be the same object, and if it is not the same, then it is considered a different object. This is reflected in the field of procedure to determine whether an object can be placed into a set such as set based on the Hashcode and equals methods. The reason that the entity class of the Federated primary Key implements the Serializable interface is that the object of the entity needs to be built first by using the Get or Load method, and the query based (the Federated primary Key) is set in and then passed in as the second parameter of the Get or Load method.
The second type: The primary key and the normal attribute are not in the same class:
1. Configuration file:
Extracts the corresponding property of the primary key to a class (called the primary Key Class), and the primary key class needs to implement the serializable interface, overriding the Equals method and the Hashcode method, for the same reason as above.
Note: In the entity class, define the primary key class as a variable. In HBM documents the first type of difference is concerned with the first Composite-id label does not have a name and class attribute.