0
我有一个任务来构建包含头和行的文档。 例如包含标题(日期,库存)和行(材料,数量,价格,总和)的股票收益文档。我的问题是我不确定我的班级架构是否正确。代码是在这里(JPA +休眠):JPA两个类之间的关系
@Entity
@Table
public class Document extends BaseEntity {
@Column
@Temporal(TemporalType.DATE)
private Date date;
@Column
@Temporal(TemporalType.DATE)
private Date createDate;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<DocumentRow> rows;
...
}
public class DocumentRow extends BaseEntity {
@ManyToOne(optional = false, cascade = CascadeType.ALL)
private Document document;
@Column(nullable = false, unique = true)
private Integer row;
...
}
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
private static final long serialVersionUID = 8171308450531596347L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; ...}
有人指出,这正好解释了他的问题 –