Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从我的表中删除行_Java_Sql_Spring_Hibernate_Model View Controller - Fatal编程技术网

Java 无法从我的表中删除行

Java 无法从我的表中删除行,java,sql,spring,hibernate,model-view-controller,Java,Sql,Spring,Hibernate,Model View Controller,我使用的是spring MVC和hibernate框架。我有两个表。分别是Team和Release。它有一对多映射。我可以从Release中删除代码,但当我从Team中删除时,会出现以下错误 HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch up

我使用的是spring MVC和hibernate框架。我有两个表。分别是Team和Release。它有一对多映射。我可以从Release中删除代码,但当我从Team中删除时,会出现以下错误

HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: 
Could not execute JDBC batch update; SQL [delete from Teams where teamID=?]; 
constraint [null]; 
nested exception is org.hibernate.exception.ConstraintViolationException: 
Could not execute JDBC batch update

首先,您需要删除版本中引用了需要删除的团队的所有记录,然后删除团队

或使用

@OneToMany(orphanRemoval=true)

由于您的表
团队
具有到表
发布
的一对一映射,因此异常清楚地表明您违反了完整性约束。你的问题

delete from teams where id=?

尝试从表
团队
中删除记录,但由于您有到
发布
的映射,因此首先需要删除表
发布
中带有
团队ID
的引用行,然后从
团队
表中删除相应行

您使用的hibernate方法是错误的~ 该守则:
“hibernate.update(sql);”

@RequestMapping(value=“/deleteteteam”,method=RequestMethod.POST)公共字符串editDeleteRecodes(@modeldattribute NewTeams NewTeams,BindingResult,@RequestParam String action,Map){Teams Teams Teams=NewTeams();Teams.setteams(NewTeams.getTeamID());Teams.delete(Teams);return“redirect:/”;}@user2991030什么?将问题中的代码不(在不可读的块中未格式化)发布到答案的注释中。在团队类中添加@OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.ALL},orphanRemoving=true)。是的,我把它放了,但仍然给出错误。。这是我的代码:@OneToMany(mappedBy=“teams,fetch=FetchType.EAGER,cascade={CascadeType.ALL},orphanRemoving=true)错误为:HTTP状态500-请求处理失败;嵌套异常为org.springframework.dao.DataIntegrityViolationException:无法执行JDBC批处理更新;SQL[从teamID=?]的团队中删除];约束[null];嵌套异常是org.hibernate.exception.ConstraintViolationException:无法执行JDBC批处理更新很酷…u答案非常清楚@重写public void delete(Teams){//TODO自动生成的方法stub session.getCurrentSession().delete(Teams);}你能给出一些示例代码吗..你应该自己试试。尝试谷歌搜索一些解决方案。最好的学习方法是通过实践。。我正在使用此..@Override public void delete(Teams){//TODO自动生成的方法stub session.getCurrentSession().delete(Teams);}我正在使用delete methode