小编toc*_*csa的帖子

使用 DiscriminatorOptions 和 orphanremoval 继承实体的 JPA OneToMany

我有一个问题,我现在好几天都无法解决。我阅读了很多文档,搜索了很多论坛,但没有找到解决方案。我继承了类,如下所示:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "nc_linktype", discriminatorType = DiscriminatorType.STRING)
@Table(name = "mk_newsletter_coupons")
@DiscriminatorOptions(force = true)
public class BaseNewsletterCoupon extends BaseEntity {...}

@Entity
@DiscriminatorValue("expire")
public class NewsletterCouponsExpire extends BaseNewsletterCoupon {

@Entity
@DiscriminatorValue("region")
public class NewsletterCouponsRegion extends BaseNewsletterCoupon {
Run Code Online (Sandbox Code Playgroud)

我想在 OneToMany 现实的多方面使用这些特定实体:

@Entity(name = "newsletter")
@Table(name = "mk_newsletters")
@Configurable
public class NewsLetter extends BasePictureEntity {

    @OneToMany(mappedBy = "newsletter", cascade = { CascadeType.ALL }, orphanRemoval = true, fetch = FetchType.LAZY)
    @IndexColumn(name = "nc_index")
    @OrderColumn(name = "nc_index")
    @OrderBy("index")
    List<NewsletterCouponsExpire> expireCoupons = new …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa one-to-many single-table-inheritance discriminator

5
推荐指数
1
解决办法
2394
查看次数