CREATE TABLE `examrequisitions` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`doctorId` bigint(20) unsigned NOT NULL,
`patientId` bigint(20) unsigned NOT NULL,
`examId` bigint(20) unsigned NOT NULL,
`dateRequisition` datetime NOT NULL,
`price` decimal(7,2) unsigned NOT NULL,
`status` enum('Realized','Opened') NOT NULL DEFAULT 'Opened',
`obs` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `doctorId` (`doctorId`),
KEY `patientId` (`patientId`),
KEY `examId` (`examId`),
CONSTRAINT `doctorId` FOREIGN KEY (`doctorId`) REFERENCES `doctors` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `examId` FOREIGN KEY (`examId`) REFERENCES `exams` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `patientId` FOREIGN KEY (`patientId`) REFERENCES `patients` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
CREATE TABLE `reports` (
`id` bigint(20) unsigned NOT NULL,
`status` enum('Validated','Invalidated') NOT NULL DEFAULT 'Invalidated',
`outcome` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
CONSTRAINT `id` FOREIGN KEY (`id`) REFERENCES `examrequisitions` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
以下查询正在运行:
INSERT INTO `systemcardiologyreports`.`reports` VALUES(1,'Invalidated', null);
但是使用Hibernate,尝试从前端发送相同的值会让我:无法添加或更新子行:外键约束失败(systemcardiologyreports
。reports
,CONSTRAINT {{1 } {id id FOREIGN KEY (
examrequisitions ) REFERENCES
id`)在更新时不执行任何操作无操作)
型号:
(
Primefaces:
@Id
@GenericGenerator(name = "generator", strategy = "foreign",
parameters = @Parameter(name = "property", value = "examrequisitions"))
@GeneratedValue(generator = "generator")
@Basic(optional = false)
@Column(nullable = false, unique = true)
private Long id;
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
@OneToOne(cascade = CascadeType.ALL)
private Examrequisitions examrequisitions;