我需要在客户和促销之间建立一种关系模型。
我们需要有关客户促销记录客户促销记录和当前客户促销记录
数据库建模很好,但我发现很难对实体建模。
我打算使用clients_promotions表仅用于关系目的,以便客户能够知道他们的促销+每次促销的当前分数。但不知道该把当前分数储存在哪里。
实体和图表:

@Entity
@Table(name = "CLIENTS")
@SecondaryTable(name = "CLIENTS_PROMOTIONS",
                pkJoinColumns = @PrimaryKeyJoinColumn(name = "ID_CLIENT"))
class Client {

    @Id
    @Column(name = "ID_CLIENT", nullable = false, unique = true)
    Long id;

    @OneToOne(cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name = "ID_USER", nullable = false, unique = true)
    User user;

    @Column(name = "NAME", nullable = false)
    String name;

    @Column(name = "BIRTHDAY", nullable = false)
    Date birthday;

    @Column(name = "EMAIL", nullable = false)
    String email;

    @Column(name = "SEX", nullable = false)
    Character sex;

    @ManyToMany
    @JoinTable(name = "CLIENTS_PROMOTIONS",
               joinColumns = @JoinColumn(name = "ID_CLIENT"),
               inverseJoinColumns = @JoinColumn(name = "ID_PROMOTION"))
    Set<Promotion> promotions;
}

-
@Entity
@Table(name = "PROMOTIONS")
class Promotion {

    @Id
    @Column(name = "ID_PROMOTION", nullable = false, unique = true)
    Long id;

    @Column(name = "ID_ESTABLISHMENT", nullable = false)
    Long establishmentId;

    @Column(name = "TITLE", nullable = false)
    String title;

    @Column(name = "LIMIT_SCORE", nullable = false)
    Long limitScore;

    @Column(name = "DESCRIPTION", nullable = false)
    String description;

    @Column(name = "REWARD", nullable = false)
    String reward;
}

java - @ManyToMany额外的列-LMLPHP

最佳答案

您需要为客户促销创建一个Entity,并将此@ManyToOne与促销和客户实体的关系建模,而不是Entity

10-05 22:52
查看更多