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的方式。

作者:山丘!

-------------------------------------------

你闻讯而来,我大喜过望,我在这等你,你又在哪呢?喜欢的话加一个“关注”呗!

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

原文地址:https://www.cnblogs.com/mengd/p/15141035.html