默认情况下,
@SequenceGenerator使用initialValue = 1和alocationSize = 50 注释的实体。
public @interface SequenceGenerator { int initialValue() default 1; int allocationSize() default 50;}Eclipselink似乎使用以下公式来计算“顺序”实体标识:
entityId = initialValue - allocationSize + INCREMENT_BY
或使用DDL:
entityId = START_WITH - allocationSize + INCREMENT_BY
回到您的特殊情况:
@SequenceGenerator( name="email-seq-gen", sequenceName="EMAIL_SEQ_GEN", allocationSize=500) // initialValue=1 (default)CREATE SEQUENCE EMAIL_SEQ_GEN START WITH 1 INCREMENT BY 500;
产生
entityId = 1 - 500 + 1 = -500 // Eclipselink error
@SequenceGenerator( name="email-seq-gen", sequenceName="EMAIL_SEQ_GEN", initialValue=1, allocationSize=500 )CREATE SEQUENCE EMAIL_SEQ_GEN START WITH 1 INCREMENT BY 500;
产生
entityId = 1 - 500 + 1 = -500 // Eclipselink error
@SequenceGenerator( name="email-seq-gen", sequenceName="EMAIL_SEQ_GEN", initialValue=500, allocationSize=500)CREATE SEQUENCE EMAIL_SEQ_GEN START WITH 500 INCREMENT BY 500;
产生
entityId = 500 - 500 + 500 = 500 // fine, but inappropriateentityId = 500 - 500 + 1000 = 1000 // incremented by 500entityId = 500 - 500 + 1500 = 1500 // incremented by 500...
为了满足您的要求,应使用以下一种:
@SequenceGenerator( name="email-seq-gen", sequenceName="EMAIL_SEQ_GEN", allocationSize=500 ) // initialValue=1 (default) but 'START WITH'=500CREATE SEQUENCE EMAIL_SEQ_GEN START WITH 500 INCREMENT BY 1;
产生
entityId = 500 - 500 + 1 = 1entityId = 500 - 500 + 2 = 2entityId = 500 - 500 + 3 = 3...
可以使用以下SQL
命令从基础数据库中删除现有序列:
DROP SEQUENCE email_seq_gen RESTRICT;
希望对您有所帮助。



