是否在多对多关系中删除级联?

时间:2016-08-31 14:27:35

标签: java mysql hibernate

我想单独删除实体,没有级联。我写这篇文章是为了避免级联,但没有明显的变化。

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;

0 个答案:

没有答案