1. Identity: used for MySQL databases. Features: Incremental
<ID name = "ID" column = "ID">
<Generator class = "Identity"/>
</ID>
Note: When using an incremental sequence for a MySQL database, you must specify the primary key as the auto_increment attribute when creating a table.
2. sequence: used for Oracle databases
<ID name = "ID" column = "ID">
<Generator class = "sequence">
<Param name = "sequence"> sequence name </param>
</Generator>
</ID>
3. Native: used across databases, produced by underlying dialects.
Default. sequence is hibernate_sequence
<ID name = "ID" column = "ID">
<Generator class = "native"/>
</ID>
Note: When native is used, Hibernate searches for the hibernate_sequence sequence in Oracle by default.
If the sequence does not exist in Oracle, an error is returned when you connect to the Oracle database.
4. HiLo: Create the hi_value table and create the next_value column by merging the IDs of the high and low bits. An initial value is required.
<ID name = "ID" column = "ID">
<Generator class = "HiLo">
<Param name = "table"> high_val </param>
<Param name = "column"> nextval </param>
<Param name = "max_lo"> 5 </param>
</Generator>
</ID>
5. sequencehilo: The same as the high and low merging ID. Create a sequence without table creation.
<ID name = "ID" column = "ID">
<Generator class = "HiLo">
<Param name = "sequence"> high_val_seq </param>
<Param name = "max_lo"> 5 </param>
</Generator>
</ID>
6. assigned: User-Defined ID;
<ID name = "ID" column = "ID">
<Generator class = "assigned"/>
</ID>
7. Foreign: used for one-to-one relationship to share the master key, the two IDs are the same.