我需要模拟客户和促销之间的关系。 我们需要有关客户促销得分 CLIENTS_PROMOTIONS_HISTORY 的历史记录以及当前得分 CLIENTS_PROMOTIONS
数据库建模很好,但我发现很难对实体进行建模。 我打算仅将 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;
}
答案 0 :(得分:0)
您需要为此<{1}}与促销和<建立 Client_Promotions 并建立Entity
关系@ManyToOne
strong>客户端实体,而不是Entity
。