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