MySQL完整性约束破坏异常:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

在单向多对一关联关系中,如果A 持有 B 的引用(即A是多端,B是一端),也就是A 的外键列指向了B 的主键。那么此时如果先删除B, 再删除A(即先删除一端,再删除A端)。那么就会抛出上述异常。

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`hibernate_3`.`orderform`, CONSTRAINT `FK_kfvdjqhg4jcbn6vggmgbf2s5h` FOREIGN KEY (`CUSTOMER_ID`) REFERENCES `customer` (`ID`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance

05-11 11:17