我正在尝试为网站设计域模型的特定部分。
我遇到的问题是用星期几 ( Day) 和时隙 ( TimeSlot)表示一种可用性矩阵。
的可能值为Day:
- 周一
- 周二
- 周三
- ...
的可能值为TimeSlot:
- 上学之前
- 早晨
- 中午
- 下午
- 放学后
- 晚上
- 夜间
目前,我有一个 JPA 实体,其中包含上述两个枚举(Day和TimeSlot)作为字段:
@Entity
public class DayToTimeSlot {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotNull(groups = { Default.class, Validation.AdvertisementCreation.class })
@Enumerated
private Day day;
@NotNull(groups = { Default.class, Validation.AdvertisementCreation.class })
@Enumerated
private TimeSlot timeSlot;
}
DayToTimeSlot然后我用所有可能的值/组合填充参考表。
最后,我有一个具有以下实例的Advertisement实体:@ManyToMany java.util.SetDayToTimeSlot
@ManyToMany
private Set<DayToTimeSlot> dayToTimeSlots;
这导致advertisement_day_to_time_slots连接表可以非常快速地增长。
没有更好的方法来模拟这个可用性矩阵吗?