The meaning of Hibernate's generator attribute
This article describes the meaning of Hibernate's generator attribute.
The generator attribute has 7 classes, and this article briefly describes the meaning and usage of these 7 classes.
Hibernate's Generator attribute has 7 classes, this article briefly describes the meaning and usage of these 7 classes.
1, Identity: for MySQL database. Features: Increment
< ID name= "id" column= "id" >
< generator class= "identity"/>
</id>
Note: The primary key is specified as the Auto_increment property for the MySQL database when you need to build the table when using an incremental sequence.
2. Sequence: for Oracle database
< ID name= "id" column= "id" >
< generator class= "sequence" >
< param name= "sequence" > Sequence name </param>
</generator>
</id>
3, native: cross-database use, generated by the underlying dialect.
Default.sequence to Hibernate_sequence
< ID name= "id" column= "id" >
< generator class= "native"/>
</id>
Note: Hibernate will find the hibernate_sequence sequence in Oracle by default when using native.
If the sequence is not in Oracle, an error is encountered when the Oracle database is connected.
4, Hilo: Through the high-low-level synthesis ID, first build table Hi_value, and then build the column Next_value. Must have an initial value.
< 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: With high-low synthesis ID, build a sequence sequence, do not build a table.
< 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 custom ID;
< ID name= "id" column= "id" >
< generator class= "assigned"/>
</id>
7, Foreign: For one-to-one relationship sharing the main health, two ID values.
The meaning of Hibernate's generator attribute