"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. (This function can be used only when no other process inserts data into the same table.
)
"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" (local)
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.
The following example:
1. Specify parameters:
<ID name = "ID" unsaved-value = "0">
<Generator class = "sequence">
<Param name = "sequence"> seq_child </param>
</Generator>
</ID>
Sequence is used and is suitable for Oracle databases;
2. Use the following methods in the configuration file to add fields to the database in SQL Server2000:
<ID name = "ID" type = "long" unsaved-value = "0">
<Column name = "ID" SQL-type = "numeric" not-null = "true"/>
<Generator class = "Identity"/>
</ID>
Here is mainly: Identity: indicates that the SQL Server2000 Database provides the sub-increment field by itself. If you want hibernate to provide it by yourself, use the increment keyword to implement it.
3. If the primary key in the table is of the string type: You can use the method provided by hibernate to realize the unique primary key:
<ID name = "ID" type = "string" unsaved-value = "null">
<Column name = "CID" SQL-type = "char (32)" not-null = "true"/>
<Generator class = "UUID. Hex"/>
</ID>
UUID. HEX: uses the 128-bit algorithm to generate a 32-Bit String. The most common method. Applicable to all databases.
* In the advanced section, implement your own primary key generator (ID generator) in hibernate)
Http://www.javaeye.com/topic/119240