I have a task to build a document which contains header and rows. for example Stock income document which contains the header (date, stock) and the rows (material, quantity, price, sum). My problem is that I am not sure that my classs architecture is right. Code is here (JPA + Hibernate):
@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; ...}