Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the generator property of Hibernate

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report