聯級管理

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。