Hibernate mapping primary key configuration mode

Source: Internet
Author: User

1. Primary KEY (ID)

Hibernate's primary key generation strategy is as follows:


1) assigned


The primary key is generated by an external program and is specified before save ().


2) Hilo


The primary key generation mechanism implemented by the HI/LO algorithm requires additional database tables or fields to provide high-level value sources.


3) Seqhilo


Similar to Hilo, the primary key generation mechanism implemented by the HI/LO algorithm requires a Sequence in the database, which is suitable for databases that support Sequence, such as Oracle.


4) Increment


The primary key is incremented in numerical order. The implementation mechanism of this method is to maintain a variable in the current application instance to hold the current maximum value, and then add 1 to the primary key each time a primary key is generated. The possible problem with this approach is that it cannot be used under a cluster.


5) identity


Adopt the primary key generation mechanism provided by the database. such as DB2, SQL Server, MySQL in the primary key generation mechanism.


6) Sequence


The primary key is generated using the sequence mechanism provided by the database. such as the sequence in Oralce.


7) native


Hibernate uses the identity, Hilo, and sequence as the primary key generation method according to the database used in its own judgment.


8) Uuid.hex


Hibernate generates 16 binary values based on the 128-bit UUID algorithm (encoded with a string of length 32) as the primary key.


9) uuid.string


Similar to Uuid.hex, the generated primary key is not encoded (length 16) and cannot be applied to the PostgreSQL database.


) Foreign


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


Examples of primary key configurations are:

<id name= "id" column= "id" type= "java.lang.Integer" > <generator class= "native"/> </id>




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.