--- title: Spring Data JPA tags: Spring, Data JPA --- ## 聯級管理 ### OneToMany * orphanRemoval - 若 Many 方在 One 方修改後無對應的關聯對象,則自動刪除。 * example: ``` @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) private List<Child> children = new ArrayList<>(); 修改前 { "id": "parent" "children": [ {"id": 1}, {"id": 2} ] } 修改後 { "id": "parent" "children": [ {"id": 2} ] } id = 1 的 child 會一併刪除 ``` * 需要 PERSIST 權限,原因未知。 * Issues * 若要透過 One 方新增 Many 方,需要給予 MERGE 權限而非 PERSIST。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up