我想单独删除实体,没有级联。我写这篇文章是为了避免级联,但没有明显的变化。
ALTER TABLE License_To_Device DROP FOREIGN KEY fk_License_has_Device_Device1;
ALTER TABLE License_To_Device
ADD CONSTRAINT fk_License_has_Device_Device1
FOREIGN KEY (device_id) REFERENCES Device (id)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
ALTER TABLE License_To_Device DROP FOREIGN KEY fk_License_has_Device_License1;
ALTER TABLE License_To_Device
ADD CONSTRAINT fk_License_has_Device_License1
FOREIGN KEY (license_id) REFERENCES License (id)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
@ManyToMany(fetch = FetchType.LAZY, cascade =
{CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "License_To_Device",
joinColumns = @JoinColumn(name = "license_id", nullable = false),
inverseJoinColumns = @JoinColumn(name = "device_id", nullable = false)
)
private List<DeviceEntity> devices;