当前位置:   article > 正文

解决报错问题:SQLIntegrityConstraintViolationException: Duplicate entry ‘4‘ for key ‘PRIMARY‘_nested exception is java.sql.sqlintegrityconstrain

nested exception is java.sql.sqlintegrityconstraintviolationexception: dupli

解决报错问题:SQLIntegrityConstraintViolationException: Duplicate entry ‘4’ for key ‘PRIMARY’

SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4813a18a] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@703e71fd] will not be managed by Spring
==> Preparing: INSERT INTO wx_main_detail ( home_id, sort_order, create_time ) values ( ?, ?, ? )
==> Parameters: 3(Integer), 1(Integer), 2019-11-27 10:51:58.805(Timestamp)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4813a18a]
2019-11-27 10:51:58.865 ERROR 119624 — [ XNIO-1 task-29] c.u.l.c.e.GlobalExceptionHandler : 异常信息uri=/sys/WxMainHome/saveEditIn,method=POST,e={}

org.springframework.dao.DuplicateKeyException:

Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘4’ for key ‘PRIMARY’

The error may involve com.ultrapower.life.mapper.WxMainDetailMapper.insertId-Inline

The error occurred while setting parameters

SQL: INSERT INTO wx_main_detail ( home_id, sort_order, create_time ) values ( ?, ?, ? )

Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘4’ for key ‘PRIMARY’

; Duplicate entry ‘4’ for key ‘PRIMARY’; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘4’ for key ‘PRIMARY’
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:242)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate S q l S e s s i o n I n t e r c e p t o r . i n v o k e ( S q l S e s s i o n T e m p l a t e . j a v a : 446 ) a t c o m . s u n . p r o x y . SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) at com.sun.proxy. SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)atcom.sun.proxy.Proxy101.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)

看报错信息,“Duplicate entry ‘4’ for key ‘PRIMARY’”表示,主键有重复的,因此,错误的原因就是值重复了,解决此类问题就是将插入的值不能是数据库已经有了的主键,

在我这个项目中主要是把表的id设置为不是自动递增(去掉勾选)

在这里插入图片描述

在我的插入语句的mapper文件里插入需要的id即可:

在这里插入图片描述

后面我的项目就跑起来了!!!!!!!!!!!!!!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/625136
推荐阅读
相关标签
  

闽ICP备14008679号