Oracle数据库自增失败

使用oracle数据库时,mybatis-plus设置自增,添加数据的时候失败

@TableId(value = "ID", type = IdType.AUTO)
private Integer id;

; ORA-01400: 无法将 NULL 插入 ("JIANG"."T_PRODUCT"."ID")

; nested exception is java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("JIANG"."T_PRODUCT"."ID")

需要在数据库设置触发器

先创建序列

create sequence SEQ_T_DEVICE

increment by 1

start with 1

minvalue 1

maxvalue 9999999

order

cache 20

cycle;

然后再这样就可以了

begin

​ select SEQ_T_DEVICE.nextval into :new.id from dual;

end;

当然,最好的解决办法就是使用UUID的方式。

posted @ 2021-08-14 16:08  山丘i  阅读(293)  评论(0编辑  收藏  举报