Hibernate Federated primary Key mapping rules and data query principle

Source: Internet
Author: User

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.

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.