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; ...}
有人指出,這正好解釋了他的問題 –