本文介绍了如何在Spring Hibernate中解决DataIntegrityViolationException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Spring Hibernate与HibernateSupportDao一起使用,当我尝试发送多行数据以存储在我的数据库中时,它在特定行上引发了DataIntegrityViolationException.相同的方案在保留在同一表的任务中起作用.即使我为当前任务使用相同的代码,我也没有遇到问题.为什么会抛出DataIntegrityViolationException,我该如何纠正?

I am using Spring Hibernate with HibernateSupportDao, when I try to send multiple rows of data to store in my db, it raises a DataIntegrityViolationException at a particular row. The same scenario has worked in remain in task on the same table. I do not get the problem even when I use the same code for the current task. Why was a DataIntegrityViolationException thrown and how can I rectify that?

推荐答案

直接从API :

基本上,这意味着休眠尝试执行某些操作,但是数据库引发了异常.最常见的情况是您要删除父级,而不是删除具有该父级外键的子级.

Basically it means that hibernate tried to do something, but the database raised an exception. Most common case might be that you are deleting a parent but not deleting a child with a foreign key to that parent.

您的传递持久性(即级联)设置是什么?

What are your transitive persistence (i.e. cascade) settings?

这篇关于如何在Spring Hibernate中解决DataIntegrityViolationException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 03:41