Hibernnate using Oracle's sequence to generate primary key auto-increment 50 for objects

Source: Internet
Author: User

Some time ago in an SSH project, using sequence in Oracle as the primary key generation strategy for the object table, the step size of the sequence is configured in the database, but when the test is run, the step size of the primary key ID is found to be 50 per increment.

Strange outside Google, find the following solution, when the ID of the entity class annotated, add a " allocationSize=1 ", for example, the primary key of the table El is configured with a sequence called " EL_SEQ ", then the GetID method using the following annotations can be resolved.

@SequenceGenerator (name= "Seqgenerator", sequencename= "El_seq", allocationsize=1)

A purely speculative test.

Then probably browse the reason, a lot of netizens said is the problem of the cache, speculation is that when the project starts, hibernate will be a one-time from the database to take 50 ID cache in memory, and then save the object from memory allocation to avoid frequent nextval to the database, This can slightly improve the database performance. The test case restarts hibernate every time, causing the ID to be incremented by 50 steps.

Attached link http://stackoverflow.com/questions/5346147/hibernate-oracle-sequence-produces-large-gap

Hibernnate using Oracle's sequence to generate primary key auto-increment 50 for objects

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.