Hibernate generator primary key generation policy, hibernategenerator

Source: Internet
Author: User

Hibernate generator primary key generation policy, hibernategenerator

"Assigned"
A primary key is generated by an external program and specified before save.

"Hilo"
The primary key generation mechanism implemented by the hi/lo algorithm requires additional database tables or fields to provide a high value source.

"Seqhilo"
Similar to hilo, the primary key generation mechanism implemented by the hi/lo algorithm requires Sequence in the database, which is suitable for databases that support Sequence, such as Oracle.

"Increment"
The primary key increments in numerical order. The implementation mechanism of this method is to maintain a variable in the current application instance to save the current maximum value, and then add 1 as the primary key each time the primary key needs to be generated. This method may cause problems: it cannot be used in a cluster.

"Identity"
Use the primary key generation mechanism provided by the database. Such as the primary key generation mechanism in DB2, SQL Server, and MySQL.

"Sequence"
Use the sequence mechanism provided by the database to generate the primary key. For example, Sequence in Oralce.

"Native"
Hibernate uses identity, hilo, and sequence as the primary key generation method based on the database used.

"Uuid. hex"
Hibernate uses the 128-bit UUID algorithm to generate a hexadecimal value (represented by a 32-Bit String After encoding) as the primary key.

"Uuid. string"
Similar to uuid. hex, the generated primary key is not encoded (Length: 16) and cannot be used in the PostgreSQL database.

"Foreign"
Use the identifier of another associated object as the primary key.

<Id> <generator> In the element is used to generate a unique identifier for the persistence class instance. hibernate provides many built-in implementations.

Increment: The identifier automatically generated by hibernate. It is used to generate a unique identifier for long, short, or int type.
Identity: The identifier generated by the underlying database (automatically increasing). The returned identifier is long, short, or int type.
Sequence: hibernate generates identifiers based on the underlying database sequence. The returned identifiers are long, short, or int type.

Hilo: uses a high/low level algorithm to efficiently generate long, short, or int type identifiers.
Uuid. hex: uses a 128-bit UUID algorithm to generate a 32-bit string type identifier.
Native: select one of identity, sequence, or hilo Based on the capabilities of the underlying database.
Assigned: assigns an identifier to the object before saving.
Foreign: identifies another associated object. And <one-to-one>.

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.