@OneToMany @ManyToOne 联级删除

商品对象SPU

    /**
     * 商品分类列表
     */
    @OneToMany(targetEntity = SPUCategoryRelation.class, cascade = CascadeType.ALL, mappedBy = "spu",orphanRemoval = true)
    private Collection spuCategoryItems;

    public SPU setSpuCategoryItems(Collection spuCategoryItems) {
        if (this.spuCategoryItems == null) {
            this.spuCategoryItems = spuCategoryItems;
            return this;
        }
        this.spuCategoryItems.clear();
        this.spuCategoryItems.addAll(spuCategoryItems);
        return this;
    }

商品分类 SPUCategoryRelation

    /**
     * 商品SPU
     */
    @ManyToOne
    @JoinColumn(name = "spu_id", nullable = false)
    private SPU spu;

 

你可能感兴趣的:(java)