Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the generator property of Hibernate

Shulou Source: shulou.com Published: 2022-06-02 08:00:26 10月13日 Update

This article mainly introduces "how to use the generator attribute of Hibernate". In the daily operation, I believe that many people have doubts about how to use the generator attribute of Hibernate. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "how to use the generator attribute of Hibernate". Next, please follow the editor to study!

1. Identity: used for MySql database. Features: increasing

< id name="id" column="id">

< generator class="identity"/>

< /id>

Note: when using an incremental sequence for a MySql database, you need to specify the primary key as the auto_increment attribute when building the table.

2. Sequence: for Oracle database

< id name="id" column="id">

< generator class="sequence">

< param name="sequence">

Sequence name

< /param>

< /generator>

< /id>

3. Native: used across databases and generated by underlying dialects.

Default.sequence is hibernate_sequence

< id name="id" column="id">

< generator class="native"/>

< /id>

Note: when using native, Hibernate will find the hibernate_sequence sequence in Oracle by default.

If the sequence is not in Oracle, an error will be reported when connecting to the Oracle database.

4. Hilo: synthesize id through high and low bits, create table hi_value first, and then create column next_value. There must be 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">

five

< /param>

< /generator>

< /id>

5. Sequencehilo: synthesize id with too high and low order, and build a sequence sequence without creating a table.

< id name="id" column="id">

< generator class="hilo">

< param name="sequence">

High_val_seq

< /param>

< param name="max_lo">

five

< /param>

< /generator>

< /id>

6. Assigned: user-defined id

< id name="id" column="id">

< generator class="assigned"/>

< /id>

At this point, the study on "how to use the generator attribute of Hibernate" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Attributes data databases sequences learning more high and low help practical next no bottom articles methods dialects features theories users knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux OPPO Reno vpn Docker