我正在使用Hibernate 4.2.21 Final,生成我使用的ID:策略= GenerationType.SEQUENCE
@Id
@SequenceGenerator(name = "ApplicationSequence", sequenceName =
"application_seq", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ApplicationSequence")
@Column(name = "application_id", unique = true, nullable = false) private Long id;
我的问题是关于为什么Hibernate以随机的方式生成我的ID ...
如1,2,3,67,89,96等...
当我的allocationSize = 1时?应该是这样的:1,2,3,4,5,6。
修改: ORACLE 12中的证据
CREATE SEQUENCE "OSYDBA"."APPLICATION_SEQ"
MINVALUE 1 MAXVALUE 9999999999999999999999999999
INCREMENT BY 1 START WITH 1
CACHE 20 NOORDER NOCYCLE NOPARTITION ;
答案 0 :(得分:0)
不要让Oracle预先缓存任何序列值:
CREATE SEQUENCE APPLICATION_SEQ
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
NOCACHE;