使用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")

需要在数据库设置触发器

Oracle数据库自增失败

先创建序列

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2021-08-11
  • 2021-11-17
  • 2021-12-05
  • 2021-12-02
  • 2021-04-01
猜你喜欢
  • 2021-06-19
  • 2022-01-23
  • 2021-10-29
  • 2021-10-09
  • 2021-08-19
  • 2021-03-30
  • 2021-07-23
相关资源
相似解决方案