无法删除或更新父行JPA

时间:2015-12-04 16:47:02

标签: java hibernate jpa

JPA不允许我从图库表中删除数据,除非我不清理图像表。当有外键时,任何人都知道如何删除数据?

 CREATE TABLE IF NOT EXISTS `gallery` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `SITE_ID` bigint(20) NOT NULL,
  `DATE_CREATED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `DATE_DELETED` timestamp NULL DEFAULT NULL,
  `DATE_UPDATED` timestamp NULL DEFAULT NULL,
  `TITLE_ENG` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `TITLE_GEO` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `TITLE_RUS` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_9smi5asvs3daquvhnydgar892` (`SITE_ID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
CREATE TABLE IF NOT EXISTS `images` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `PATH` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `SITE_ID` bigint(20) DEFAULT NULL,
  `GALLERY_ID` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_ewyghuij49l5wp3pnxnbg41en` (`GALLERY_ID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ;
ALTER TABLE `images`
  ADD CONSTRAINT `FK_ewyghuij49l5wp3pnxnbg41en` FOREIGN KEY (`GALLERY_ID`) REFERENCES `gallery` (`id`);

当我尝试删除它时,显示日志中的错误

ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Cannot delete or update a parent row: a foreign key constraint fails (`pp`.`images`, CONSTRAINT `FK_ewyghuij49l5wp3pnxnbg41en` FOREIGN KEY (`GALLERY_ID`) REFERENCES `gallery` (`id`))

0 个答案:

没有答案