這是我的物體
package com.nimesia.sweetvillas.entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "specs", schema = "crm")
public class SpecEntity extends AbsEntity {
@Id
@Column(name = "spec_id")
private @Getter @Setter String id;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "specs_translations",
schema="crm",
joinColumns = @JoinColumn(name = "spec_id"),
inverseJoinColumns = @JoinColumn(name = "translation_id")
)
private @Getter @Setter
List<TextEntity> texts;
}
如您所見,TextEntity 存在 oneToMany 關系。這種關系是通過 specs_translations 表生成的。
問題來了。
在創建 specEntity 時,我還可以創建它的子物體(在這種情況下是翻譯)。在資料庫中,將創建 specs_translations 中的參考和翻譯中的記錄(包含 textEntities 記錄的表)。應該如此。
但是當涉及到從我的 SpecEntity 中更新和洗掉 TextEntity 時,雖然 specs_translations 中的參考被洗掉,但相對翻譯記錄仍然存在。這會導致如下圖所示的情況

當我在 specs_translations 中洗掉它的參考時,如何洗掉翻譯中的記錄?我想通過 JPA 而不是通過 DB 來實作這一點。
uj5u.com熱心網友回復:
我解決了。我只是將 orphanRemoval 設定為“true”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/446715.html
