在一对多关系中更新子实体

huangapple 未分类评论41阅读模式
英文:

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=&quot;trm_agreements&quot;)
public class Agreement{

    
    @Id
    private Long id;

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = &quot;TRAGT_ID&quot;)
    private List&lt;SubAgreement&gt; subAgreements;

    // rest of the params
}

And a child entity

@Entity
@Table(name=&quot;trm_sub_agreements&quot;)
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.

huangapple
  • 本文由 发表于 2020年4月9日 21:40:41
  • 转载请务必保留本文链接:https://java.coder-hub.com/61122519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定