Significance of the generator attribute in hibernate

Source: Internet
Author: User

 

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.