Hibernate Oracle Sequence Skills _oracle

Source: Internet
Author: User
Tags oracle database
one, for the table to create a self-growth from the paragraph there are two, one is different tables using their own sequence , the following methods:

1, in Oracle sequence first create sequence

Create sequence Seq_idminvalue 1start with 1increment by 1cache 20;

2, the configuration in your Hbm.xml

seq_id

When you insert the data again, Hibernate automatically generates the following statement:

Hibernate:select Seq_id.nextval from dual Hibernate:insert into YXJK. T_YXJK_WHRYTXL (XM0000, ZW0000, LXDH00, SJHM00, dzyj00,ip0000, ID0000) VALUES (?) , ? , ? , ? , ? , ? , ? )

Automatically generates the next sequence value, and then inserts the object into the table. When used, it is important to note that the requirement for the primary key of the sequence is Shor,long, or integer hibernate.

  Second, there is a way to use the public sequence, which can not specify the table to use the sequence, then the corresponding hbm.xml content is:

Then create a common sequence object named Hibernate_sequence

Create  Sequence hibernate_sequence

MinValue 0

MaxValue 99999999

Start with 10000

Increment by 1  ;

three, considerations

If the database is ported from other databases, such as SQL Server, the starting value for creating the sequence should be larger than the largest ID value in the current table, otherwise an error occurs because sequence does not maintain that the existing values are duplicated before the library.

1, sequence: for Oracle database

Sequence name

2, native: used across databases, generated by the underlying dialect.  

Default.sequence to hibernate_sequence

Note: Hibernate will find the hibernate_sequence sequence in Oracle by default when using native. If the sequence is not in Oracle, an error will be encountered even with the Oracle database.

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.