oracal自增id

1.建库
drop table MESSAGE_INFO
create table MESSAGE_INFO
(
   ID                   NUMBER(10)           not null,
   TITLE                VARCHAR2(100)        not null,
   CONTENT              VARCHAR2(1000)       not null,
   TYPE                 VARCHAR2(20)         not null,
   SCOPE                VARCHAR2(100),
   CREATETIME           NUMBER(14)           not null,
   EXPIRETIME           NUMBER(14)           not null,
   MEMO                 VARCHAR2(200),
   constraint PK_MESSAGE_INFO primary key (ID)
)
2.建序列sequence
drop sequence SEQ_MESSAGE_INFO
create sequence SEQ_MESSAGE_INFO
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 100
3.建触发器trigger
create or replace trigger TRI_MESSAGE_INFO
before insert on MESSAGE_INFO
for each row
begin
  select SEQ_MESSAGE_INFO.nextval into:new.id from sys.dual;
end;
4.实体类MESSAGE_INFO配置
@Id
@SequenceGenerator(name="MESSAGE_INFO_GENERATOR",sequenceName="SEQ_MESSAGE_INFO",allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="MESSAGE_INFO_GENERATOR")
private Long id;//主键id

你可能感兴趣的:(ora)