英文:
Updating child entities in One-To-Many relationship
问题
我有一个父实体
@Entity
@Table(name="trm_agreements")
public class Agreement{
@Id
private Long id;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "TRAGT_ID")
private List<SubAgreement> subAgreements;
// 其余参数
}
还有一个子实体
@Entity
@Table(name="trm_sub_agreements")
public class SubAgreement{
@Id
private Long id;
// 其余参数
}
现在,假设有3个子协议与1个协议相关联,我想通过添加1个更多的子协议和删除1个现有的子协议来更新该协议。
我不确定如何在Spring Boot中实现这一点。
英文:
I have a parent entity
@Entity
@Table(name="trm_agreements")
public class Agreement{
@Id
private Long id;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "TRAGT_ID")
private List<SubAgreement> subAgreements;
// rest of the params
}
And a child entity
@Entity
@Table(name="trm_sub_agreements")
public class SubAgreement{
@Id
private Long id;
// rest of the params
}
Now, Lets say there are 3 sub-agreements associated with 1 agreement and I want to update that Agreement by adding 1 more sub-agreement and deleting 1 existing sub-agreement.
I'm not sure how to do this using springboot.
专注分享java语言的经验与见解,让所有开发者获益!
评论