JPA使用笔记

  1. 关联关系由@JoinColumn方维护,使用OneToMany时,推荐的做法是一的这方放弃维护,使用mapperBy来关联。此时如果需要在一的这方使用级联保存,并自动保存外键id。则重写get方法,在set集合时绑定关系.
    参考文章
    public void setVolumes(Set<ProfileVolume> volumes) {
        volumes.forEach(profileVolume -> profileVolume.setAppServiceProfile(this));
        this.volumes = volumes;
    }
posted @ 2022-06-13 18:03  小小记录本  阅读(26)  评论(0编辑  收藏  举报