个人博客导航页(点击右侧链接即可打开个人博客):大牛带你入门技术栈
领域驱动设计核心是领域对象识别,一切操作皆是对象,这也是面向对象编程所倡导的。在设计实体属性时,除了数据库能识别的标准数据类型外,也越来越多考虑复合型的对象属性。让我们的设计视角为数据存储的层面转向客观事物存在的实际表象。ORM框架也就是为此提供技术支撑,至少JPA朝此方向不断完善的。
先上代码:(此代码主要为展示功能而设计,不一定具体设计的合理性,由于篇幅代码略有删减)
@Entity
public class SaleOrder implements Serializable {
@Column(unique = true, updatable = false)
private String orderCode;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "stationCode", column = @Column(name = "in_station_code")),
@AttributeOverride(name = "storage.storageCode", column = @Column(name = "in_storage_code"))
})
private Station inStation;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "stationCode", column = @Column(name = "out_station_code")),
@AttributeOverride(name = "storage.storageCode", column = @Column(name = "out_storage_code"))
})
private Station outStation;
private LocalDateTime saleTime;
private Address address;
@ManyToOne(cascade = CascadeType.REFRESH)
@JoinColumn(name = "memberCode", referencedColumnName = "memberCode")
private Member member;
@Enumerated(EnumType.STRING)
private OrderState orderState;
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinColumn(name = "saleOrderCode", referencedColumnName