Assigned
The assigned method generates a primary key value by the program and will throw an exception if it is specified before save ()
Feature: The generated value of the primary key is determined entirely by the user, regardless of the underlying database. The user needs to maintain the primary key value and specify the primary key value before calling Session.save ().
Hilo
Hilo uses a high-low algorithm to generate a primary key, and the low-level algorithm uses a high value and a low value, and then stitching together the two values of the algorithm as the unique primary key in the database. The Hilo approach requires additional database tables and fields to provide high-level value sources. By default, the table used is
Hibernate_unique_key, the default field is called Next_hi. Next_hi must have a record otherwise an error will occur.
Features: Additional database table support is required to guarantee the uniqueness of the primary key in the same database, but it does not guarantee the uniqueness of the primary key between multiple databases. The Hilo primary key generation method is maintained by hibernate, so Hilo is not independent of the underlying database, but should not manually modify the values of the tables used by the Hi/lo algorithm, or it will cause duplicate exceptions for the primary key.
Increment
The increment method generates a new primary key value in a way that automatically increases the primary key value, but requires support from the underlying database sequence. such as ORACLE,DB2 and so on. You need to include the settings for the increment flag in the map file xxx.hbm.xml.
Features: Maintained by hibernate itself, suitable for all databases, not suitable for multi-process concurrent update database, suitable for a single process to access the database. cannot be used in a clustered environment.
Identity
Identity was based on the underlying database to support autogrow, and different databases used different primary key growth modes.
Features: Related to the underlying database, requires the database to support identity, such as MySQL is auto_increment, SQL Server is identity, the supported databases are MySQL, SQL Server, DB2, Sybase and Hypersonicsql. The identity does not require hibernate and user intervention, it is easier to use, but it is not easy to migrate programs between different databases.
Sequence
Sequence requires the underlying database to support sequence methods, such as Oracle database, etc.
Features: The support sequence of the underlying database is required, the database that supports the sequence has DB2, POSTGRESQL, Qracle, sapdb, and so on, porting the program between different databases, especially from the database that supports the sequence to the database that does not support the sequence needs to modify the configuration file
Native
The native primary key generation method automatically selects the identity, Sequence, and Hilo primary key generation methods based on different underlying databases.
Features: Depending on the underlying database, different primary key generation methods are used. Because Hibernate uses different mapping methods based on the underlying database, it is easy to migrate programs, which can be used if multiple databases are used in a project.
Uuid
The UUID uses the 128-bit UUID algorithm to generate the primary key, which can guarantee the uniqueness of the primary key under the network environment, and can guarantee the uniqueness of the primary key under different database and different server.
It can guarantee the uniqueness of the primary key in the database, and the generated primary key occupies more storage space.
Foreign
Foreign is used in a one-to-one relationship to ensure uniqueness of the generated primary key, supporting SQL Server and MySQL.
Hibernate uses the primary key generation method.