Could not execute JDBC batch update; SQL [delete from role where roleId=?]; constraint [null]; neste
阿新 • • 發佈:2019-01-04
今天在寫多個刪除功能的時候出現了這麼一個錯誤:意思是刪除操作的時候,沒有找到對應的外來鍵。
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";
}
….如果知道為什麼會多出一個空格的,請在評論下告訴我….