The primary key generation strategy of Hibernate framework Learning Generator

Source: Internet
Author: User

1) Manual control

Assigned (unrestricted type)

2) Automatic database generation

UUID (String type)

Increment (integer numeric type)

Identity (integer numeric type)

Sequence (integer numeric type)

Native (integer numeric type)

Assigned policy is an ID generation strategy for manual control of input data model OIDs by programmers
Assigned policy does not qualify the type of ID field in the database
Assigned policy does not guarantee the non-repeatability of IDs
Assigned policies are usually used in conjunction with externally customized ID generation policies, otherwise they will be of great risk
The assigned strategy is relatively simple for cluster database ID control and can also be understood as "do whatever"
Late mates some primary key auto-increment tool classes (uuidservice) complete
Adding the caching mechanism to the Uuidservice Foundation to improve its efficiency effectively

=======

The UUID policy is an OID generation strategy that is calculated by combining the following 4 kinds of data
IP Address
JVM startup time (accurate to 250ms)
Current system time
Counters provided by the JVM (guaranteed unique)
UUID policy requires that the ID field in the database be a string type
The UUID policy guarantees the uniqueness of the ID and is therefore not risky

=========

Increment policy is an ID generation policy that generates an OID from hibernate internal control
Increment policy requires that the ID field in the database be an integer numeric type
The increment policy first extracts the currently used maximum ID value from the corresponding database table Max, and then on this basis +1, provides to the current to manipulate the data, the completion of the primary key unique growth, compatible with the database
Although the increment policy can guarantee the uniqueness of the ID, it is possible to obtain the same max value when multiple connections operate on one table, resulting in the same ID, so more configuration is required to control the concurrency policy of the database

=====

An identity policy is an ID generation policy that generates an OID from the database's underlying control
The identity policy requires that the ID field in the database be an integer numeric type, and that it is required to be set to a self-increment property
Identity can only be applied to database implementations that provide primary key auto-increment policies, are not fully compatible with all databases, MySQL is available
The identity policy is implemented at the bottom of the database, even if an ID is not used and does not affect the acquisition of the next ID, so thread safety

=========

Sequence policy is an ID generation strategy for generating OID from database underlying control
Sequence policy requires that the ID field in the database be an integer numeric type
Sequence can only be applied to database implementations that provide sequence support, are not fully compatible with all databases, Oracle is available
The sequence policy is implemented by the database, and the ID generation control is referred to the database management, which is a thread-safe policy

============

Native strategy is a kind of design OID generation strategy
Native automatically selects the corresponding ID generation policy in the following various build policies based on the type of database you are using
Identity
Sequence
Hilo

==========

Composite PRIMARY key/Federated primary key/multi-primary key

Composite primary key refers to the use of two or more than two attributes in a data model to differentiate data as a unique identity
Composite primary keys are rarely used in the current development, primarily for compatibility with early legacy systems
Composite primary Key Development method:

Composite primary key and primary key can only select one of the use

The primary key generation strategy of Hibernate framework Learning Generator

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.