Hibernate's Generator property

Source: Internet
Author: User

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

    1. < ID name="id" column= "id">
    2. < generator class="Identity"/>
    3. </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

  1. < ID name="id " column="id">    
  2. < generator class="sequence">
  3. < param name="sequence"> sequence name < /param>    
  4. < /generator>
  5. < /id>

3, native: cross-database use, generated by the underlying dialect.
Default.sequence to Hibernate_sequence

  1. < ID name="id " column="id">    
  2. < generator class="native"/>
  3. < /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.

  1. < ID name="id " column="id">    
  2. < generator class="Hilo">
  3.        <  param name= "table" > high_val <  /param >    
  4.         <  param name= "column" > nextval <  /param >    
  5. < param name="Max_lo">5< /param>
  6. < /generator>
  7. < /id>

5, Sequencehilo: With high-low synthesis ID, build a sequence sequence, do not build a table.

  1. < ID name="id" column="id " >
  2. < generator class="Hilo">
  3. < param name="sequence">high_val_seq< /param>    
  4. < param name="Max_lo">5< /param>
  5. < /generator>
  6. < /id>

6, Assigned: User custom ID;

  1. < ID name="id " column="id">    
  2. < generator class="Assigned"/>
  3. < /id>

7, Foreign: For one-to-one relationship sharing the main health, two ID values.

Hibernate's Generator property

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.