Hibernate primary key generation strategy explanation--easy to understand

Source: Internet
Author: User

The primary key generation strategy refers to the <grnerator class= "native"/>

1, native
For Oracle using the Sequence method, for MySQL and SQL Server using identity (the generation of the main key generating mechanism), native is the primary key generation work to the database to complete, hibernate regardless (very often)

2, assigned
When inserting data, the primary key is added by the user himself, and hibernate (very often)

3, Increment
When inserting the data, Hibernate adds an additional primary key to the primary key, but a hibernate instance maintains a counter, so you cannot use this method when multiple instances are running

4, Sequence
Call the database sequence to generate the primary key, set the sequence name, or hibernate cannot find:
<param name= "sequence" >NAME_SEQ</param> (very common in Oracle)

5. Identity
Using the self-added fields of SQL Server and MySQL, this method cannot be placed in Oracle, and Oracle does not support the sequence field, which is used in MySQL and SQL Server.

6, Hilo
Use the Hilo build policy to create an extra table in the database, with the default table name Hibernate_unique_key, the default field of type Integer, and the name Next_hi (less)
We can also set our own custom table names and field names.
<id name= "id" type= "integer" >
<column name= "id"/>
<generator class= "Hilo" >
<param name= "My_unique_key"/>
<param column= "Next_hi"/>
</generator>
</id>

7, Sehilo
Implemented through the Hilo algorithm, but the primary key history is stored in Sequence and is suitable for databases that support Sequence, such as Oracle (less)

8, Uuid.hex
Hibernate will figure out a 128-bit unique value insertion

9, Uuid.string
Hibernate will figure out a 16-bit value to insert

10, Foreign
Use fields from external tables as primary keys

11, select
        use triggers to generate primary keys (primarily for early database primary key generation mechanisms, less)

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.