1) assigned
The primary key is generated by an external program, without hibernate involvement.
2) Hilo
The primary key generation mechanism implemented by the HI/LO algorithm requires additional database tables to save the primary key generation history state.
3) Seqhilo
Similar to Hilo, the primary key generation mechanism implemented by the HI/LO algorithm is simply that the primary key historical state is saved in sequence and is applicable to 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 if there are multiple instances accessing the same database, the different instances may generate the same primary key as each instance maintains the primary key state, causing the primary key to repeat the exception. Therefore, this approach must be avoided if there are multiple instance accesses to the same database.
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 identity, Hilo, sequence as the primary key generation method according to the underlying database.
8) Uuid.hex
Hibernate generates a 16 binary value based on a 128-bit unique value generation algorithm (encoded with a string of length 32) as the primary key.
9) uuid.string
Similar to Uuid.hex, only the generated primary key is not encoded (length 16). Problems (such as PostgreSQL) may occur in some databases.
) Foreign
Use the field of the external table as the primary key.
In general, generating primary keys using the Uuid.hex approach provides the best performance and database platform adaptability.
In addition, due to the common database, such as Oracle, DB2, SQL Server, MYSQL, etc., provides an easy-to-use primary key generation mechanism (auto-increase field or sequence). We can use Generator-class=native's primary key generation method on the primary key generation mechanism provided by the database. It is worth noting, however, that some databases provide a primary key generation mechanism that is not necessarily the most efficient, and that large amounts of concurrent insert data can cause interlocking between tables. The primary key generation mechanism provided by the database is often done by saving the current primary key state in an internal table (for example, the current maximum and increment is maintained in this internal table for the self-incrementing primary key), and then each time the data is inserted, the maximum value is read and the increment is used as the primary key for the new record. This new maximum value is then updated back to the internal table so that an insert operation can cause multiple table reads and writes inside the database, along with the locking unlock operation of the data, which has a significant impact on performance. Therefore, it is recommended to use Uuid.hex as the primary key generation mechanism for systems with high concurrent insert requirements.