我有一個問題。當我使用 jpa 從類別表中洗掉任何資料時;它會洗掉它在位置表中連接到的父級以及該父級連接到的所有類別。
樣本;
我的分類資料
如果我在類別表中洗掉 id 113;它洗掉類別表中的所有 location_id 1 和位置表中 id 為 1 的位置。結果,任何 location_id 為 1 的內容都會被洗掉。
我的桌子
我的位置 :
@Getter
@Setter
@Entity
@Table(name = "location_entity")
public class LocationEntity extends BaseEntity {
// some properties
@Fetch(FetchMode.SUBSELECT)
@OneToMany(mappedBy = "categorylocation")
private List<CategoryEntity> categoryEntityList;
// some properties
}
我的分類:
@Getter
@Setter
@Entity
@Table(name = "category_entity")
public class CategoryEntity extends BaseEntity {
// some properties
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "location_id")
private LocationEntity categorylocation;
// some properties
}
uj5u.com熱心網友回復:
此行為與ManyToOne注釋的級聯引數有關,從 categorylocation 屬性中洗掉將解決此問題。cascade = CascadeType.ALL
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/445631.html
