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