Could not execute JDBC batch update; SQL [delete from role where roleId=?]; constraint [null]; neste

今天在写多个删除功能的时候出现了这么一个错误:意思是删除操作的时候,没有找到对应的外键。


Cannot delete or update a parent row: a foreign key constraint fails (`ssh03`.`role_privilege`, CONSTRAINT `FK45FBD628F05C38CB` FOREIGN KEY (`role_id`) REFERENCES `role` (`roleId`))
Cannot delete or update a parent row: a foreign key constraint fails (`ssh03`.`role_privilege`, CONSTRAINT `FK45FBD628F05C38CB` FOREIGN KEY (`role_id`) REFERENCES `role` (`roleId`))
Could not execute JDBC batch update
Could not execute JDBC batch update; SQL [delete from role where roleId=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [delete from role where roleId=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

在网上找了很久,都没有找到对应的错误。。我的删除操作是先查找Role对象,再通过删除它

后来debug起来又是匪夷所思的:后台能够得到外界传递过来的id

这里写图片描述

在查询对象的时候,就死活查不了外键的数据【让我搞了很久很久】。。

这里写图片描述

最后发现id上多了一个空格???????至于为什么多了一个空格,,我现在还不知道。。。于是把空格去掉,就解决这个bug了。。。


    /*批量删除*/
    public String deleteSelect() {
        for (String s : selectedRow) {

            roleServiceImpl.delete(s.trim());
        }
        return "list";
    }

….如果知道为什么会多出一个空格的,请在评论下告诉我….

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值