当我尝试在for($i=$rowcount; $i>0; $i--){
$id = $array[$i];
$query = "DELETE FROM table WHERE ID=:id AND Order=:order";
$stmt = $conn->prepare($query);
$stmt->execute(array('id' => $id, 'order' => $i));
}
的帮助下使用其ID从users表中删除User
时,会出现异常:
Hibernate
和代码:
Caused by:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`ewp`.`user_task_history`, CONSTRAINT `FK_mkjvq9fr0e1hdgi3ekl0hluuu` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`))`.
当我尝试删除具有外键的其他对象时,会发生同样的事情。有没有其他方法让Hibernate自己删除所有具有我想要删除的对象的外键链接的对象?