仅在某些特定条件下加载表(@Where)

时间:2018-09-21 06:59:47

标签: jpa

我要执行的操作是仅加载带有promotion.enabled = 1和PromotionType.enabled = 1的促销。 我试图在两个表中都添加@Where批注,但是当我将promotionType设置为0时,出现错误。 另一方面,我也尝试将@WhereJoinTable子句添加到promotionType,但是没有得到预期的结果。有帮助吗?

第一个:

@Entity
@Table(name = "HOTEL_PROMOTION")
@Where(clause = "enabled=1")
public class Promotion implements Serializable {

    private static final long serialVersionUID = 257070400893576505L;

    @Id
    @Column(name = "PROMOTION_ID")
    private Long id;

    @Column(name = "CODE")
    private String code;

    @Column(name = "NAME")
    private String name;

    @Column(name = "PRIORITY")
    private Long priority;

    @ManyToOne
    @JoinColumn(name = "PROMOTION_TYPE_ID")
    @WhereJoinTable(clause = "enabled=1")
    private PromotionType promotionType;

    @Column(name = "ENABLED")
    private Boolean enabled;
}

第二个:

@Entity
@Table(name = "HOTEL_PROMOTION_TYPE")
public class PromotionType implements Serializable {

    private static final long serialVersionUID = -8359165117733458987L;

    @Id
    @Column(name = "PROMOTION_TYPE_ID")
    private Long id;

    @Column(name = "CODE")
    private String code;

    @Column(name = "NAME")
    private String name;

    @Column(name = "STYLE")
    private String style;

    @Column(name = "ENABLED")
    private Boolean enabled;
}

0 个答案:

没有答案