Hibernate调用SEQ_name.nextval
但是如果allocationSize
它大于1,它会通过allocationSize递减它并将其递增1.
下一个(allocationSize-1)密钥生成在没有与数据库通信的情况下通过增加1来完成.
因此,如果使用默认值allocationSize
50,则会产生两种后果:
序列必须INCREMENT BY
设置为相同的值 allocationSize
要将序列与数据库中的现有键对齐,请将其设置START WITH
为
max(ID)+ allocationSize
这是一个小例子
-- START WITH = max(ID) + allocation size -- INCREMENT BY = allocation size -- e.g. if 100 is the last key, -- to start with a key 101 - set START WITH to 150 CREATE SEQUENCE hib_seq START WITH 150 INCREMENT BY 50; select hib_seq.nextval - 50 + 1 from dual; 101 -- 49 times Hibernate performs increase by 1 - keys 102 to 150 -- new sequence generation select hib_seq.nextval - 50 + 1 from dual; 151