错误信息:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: Too many keys are generated. There are only 1 target objects. You either specified a wrong ‘keyProperty’ or encountered a driver bug like #1523.
这个错误通常是由于使用了自动生成键的配置,但在插入操作中生成了多个键,导致与预期不符。就是一个实体插入完数据要写主键的时候发生了多个主键写到一个实体上。
我用的是mybatis的xml sql 是 replace into (album_id,app) values('','')
然后批量新增数据时,运营不小心在批量新增中产生了唯一索引冲突的数据,造成了这种错误。
总结:即想把主键插入到实体中,又想遇到存在的记录不处理,还是老老实实多写几步,先判断唯一索引是否存在吧。因为 replace into 和 useGeneratedKeys="true" keyProperty="control.id"
不能一起使用,只要唯一索引冲突 就会报错。