## Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '219' for key 'PRIMARY'
### The error may involve com.atguigu.gmall.manage.mapper.PmsBaseAttrValueMapper.insertSelective-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO pms_base_attr_value ( id,value_name,attr_id ) VALUES( ?,?,? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '219' for key 'PRIMARY'
; SQL []; Duplicate entry '219' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '219' for key 'PRIMARY'
org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '219' for key 'PRIMARY'
### The error may involve com.atguigu.gmall.manage.mapper.PmsBaseAttrValueMapper.insertSelective-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO pms_base_attr_value ( id,value_name,attr_id ) VALUES( ?,?,? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '219' for key 'PRIMARY'
; SQL []; Duplicate entry '219' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '219' for key 'PRIMARY'
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)<
springboot+mybatis com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException异常解决方案
最新推荐文章于 2022-10-02 18:04:37 发布
在尝试使用SpringBoot和MyBatis插入数据时遇到MySQL的IntegrityConstraintViolationException,错误提示为Duplicate entry '219' for key 'PRIMARY'。问题出在尝试插入已存在的主键值。解决方案是在模型类中添加@GeneratedValue(strategy = GenerationType.IDENTITY)注解,允许数据库自增主键。

最低0.47元/天 解锁文章
4341

被折叠的 条评论
为什么被折叠?



