记一次mybatis-plus3.5.0升级3.5.2高版本插入报错
背景
据说3.5.0存在风险,所以要将mybatis-plus(以下简称mq)升级为3.5.2版本,但发现所有继承mq的BaseMapper的mapper实现插入时都会报错空指针
报错示例:
nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.lang.NullPointerException\r\n### The error may exist in file [G:\\githup\\littleRui\\trunk\\source\\cloud-service\\target\\classes\\com\\ruijie\\biz\\mapper\\xml\\TempChannelRacePointMapper.xml]
### The error may involve com.ruijie.biz.mapper.TempChannelRacePointMapper.generateRunningData
### The error occurred while executing an update
### Cause: java.lang.NullPointerException
解决过程
像这种没有明确报错行数的只能debug一点点进去看了,先是找到3.5.2版本的报错代码具体行数
没错,报错的很莫名其妙,因为id生成器是null,所以空指针了. 这里是因为我的工程涉及到多数据源,当时配置的globalException没有存id生成器!
那为什么3.5.0版本一直是好好的??
a ?~
因为之前没使用到id生成器,id属性是手动存的值,所以没有问题.
解决方案
1、将id生成器加入到globalConfig中
2、在do类的id上添加TableId注解,并指定idType为NONE或INPUT
3、修改全局的idType,级别参考上面的