1.异常代码
org.springframework.dao.DuplicateKeyException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'R12388' for key 'return_bill_code' ### The error may involve com.bjucloud.wms.bill.dao.ReturnBillDAO.save-Inline ### The error occurred while setting parameters ### SQL: insert into return_bill ( `status`, `return_bill_code`, `return_bill_wave_id`, `waybill_id`, `waybill_code`, `owner_id`, `owner_code`, `supplier_id`, `supplier_code`, `customer_id`, `customer_code`, `customer_name`, `remark`, `access_time`, `operate_time`, `inbound_time`, `logistics_center_code`, `warehouse_code`, `dock_name`, `acceptance_name` ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
调用持久层进行保存或更新的时候,跟主键或唯一性约束(索引)冲突了,会抛出Duplicatekeyexception异常
2.解决办法
调用持久层类的进行保存或更新前进行条件约束
删除唯一性索引
改唯一性索引为普通索引
捕获异常处理
注意:本文归作者所有,未经作者允许,不得转载