On delete set null in hibernate in @OneToMany

后端 未结 3 2023
南笙
南笙 2021-01-07 17:43

I have a Department entity which relations are as follows:

  1. Many departments can be in one parent department:

    
    
            
3条回答
  •  感动是毒
    2021-01-07 18:35

    Just code it:

    for (Department child : parent.getChildren()) {
        child.setParentDepartment(null);
    }
    session.delete(parent);
    

提交回复
热议问题