com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for

背景:用Eclipse+MySQL做项目的时候,从项目中保存数据

 

问题:

出现错误

org.springframework.transaction.TransactionSystemException:Could not commit JPA transaction;

nested exception isjavax.persistence.RollbackException: Exception [EclipseLink-4002]

(Eclipse Persistence Services -2.4.0.v20120608-r11652):

org.eclipse.persistence.exceptions.DatabaseException

Internal Exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:

Duplicate entry '2' for key 'PRIMARY'

Error Code: 1062

 

关键信息:

1MySQLIntegrityConstraintViolationException是指外键出错了(我的问题是所改主键作为了其他表的外键)

2Duplicate entry '2'for key 'PRIMARY'是指主键重复了

 

解决办法:把数据库中那条主键为2的数据的主键改为其他值,再执行保存,就OK啦!

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值