About hibernate's Oracle primary key ID generation policy UUID, native, and Sequence

Source: Internet
Author: User

1. UUID is a 32-Bit String, so the size of the database primary key field must be greater than or equal to 32 characters. In addition, if a trigger and sequence are set in the database table, even if the uuid primary key generation policy is used, the uuid will become invalid when hibernate inserts data, instead, the value in sequence is used as the primary key ID. It is equivalent to using UUID as the primary key ID, but it is overwritten by the value in sequence before insertion. Note This. The trigger that deletes the table can be restored.

 

2. Native means that the implementation of the Primary Key Generation Mechanism will be decided by hibernate. Hibernate uses a specific primary key generation method for different databases based on the definition of the underlying database adapter dialect. (Auto-incrementing fields are used for sqlserver and MySQL, and auto sequence is used for Oracle to generate primary keys)

Note: In this case, Hibernate uses the sequence hibernate_sequence by default. If it is not set in Oracle, the console will generate"Hibernate: Select hibernate_sequence.nextval from dual
Caused by: Java. SQL. sqlexception: ORA-02289: sequence (number) does not exist. Add a sequence named hibernate_sequence to Oracle.

You can also use the following method to specify which sequence to use:

<Generator class = "native">
<Param name = "sequence"> huser_seq </param></Generator>

 

3. Sequence means that the sequence mechanism provided by the database will be used to generate the primary key. In the HBM. xml ing file, if this primary key ing mechanism is used, you must specify the sequence used to generate the primary key. For example:

<ID name = "userid" type = "Java. Lang. Long">


<Column name = "user_id" precision = "22" scale = "0"/>
<Generator class = "sequence">
<Param name = "sequence"> seq_user </param>
</Generator>
</ID>

ArticleSource: http://muzixiang.iteye.com/blog/858781

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.