在Oracle中:
创建序列
create sequence seq_newsId increment by 1 start with 1 maxvalue 999999999;
得到序列的SQL语句
select seq_newsid.nextval from sys.dual;
删除序列的SQL
DROP SEQUENCE seq_newsId;
这样Oracle中序列就创建好了。
在Jpa中:
实体类配置
1 @Id 2 3 @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="mseq") 4 5 @SequenceGenerator(name="mseq",sequenceName="seq_newsId",allocationSize=1) 6 7 @Column(name = "ENTID", unique = true, nullable = false, precision = 22, scale = 0) 8 9 public long getEntid() { 10 11 return this.entid; 12 13 }
sequenceName 是自己在oracle中创建的序列。allocationSize要指定为1,否则它会按照默认50个数字增长。