在正在构建的系统中,Invoice
具有billedFrom
,billedTo
和shippedTo
,它们都是实体Branch
。我不知道如何在Branch类上定义此关系的@OneToMany
(如果确实是映射此关系的正确方法)这一面。这是我到目前为止所做的
分支实体
@Entity
@Getter
@Setter
@NoArgsConstructor
public class Branch extends AuditModel implements Serializable {
private static final long serialVersionUID = -8841725432779534218L;
@Column(name = "branch_name", length = 25, nullable = false)
private String branchName;
@Column(length = 15, unique = true)
private String gstin;
@Column(name = "vat_tin", length = 11, nullable = true)
private String vatTin;
private Address address;
private Boolean sez;
public Boolean isSez() {
return sez;
}
@OneToOne(fetch = FetchType.LAZY)
@JoinTable(name = "branch_contact", joinColumns = @JoinColumn(name = "branch_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "contact_id", referencedColumnName = "id"))
private Contact contact;
}
发票实体
@Entity
@Getter
@Setter
@NoArgsConstructor
public class Invoice extends AuditModel implements Serializable {
private static final long serialVersionUID = 1560474818107754225L;
@Column(unique = true, length = 20)
private String invoiceNumber;
@Column(nullable = false, length = 25)
private String placeOfSupply;
private Double roundOff;
@Temporal(TemporalType.DATE)
@Column(nullable = false)
private Date invoiceDate;
@Temporal(TemporalType.DATE)
@Column(nullable = false)
private Date dueDate;
@Column(nullable = false)
private String paymentTerms;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "invoice_line_items", joinColumns = @JoinColumn(name = "invoice_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "line_item_id", referencedColumnName = "id"))
private List<LineItem> lineItems;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "invoice_id", referencedColumnName = "id")
private List<Payment> payments;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "billed_from_invoices", joinColumns = @JoinColumn(name = "invoice_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "branch_id", referencedColumnName = "id"))
private Branch billedFrom;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "customer_invoices", joinColumns = @JoinColumn(name = "invoice_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "branch_id", referencedColumnName = "id"))
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "billed_to_invoices", joinColumns = @JoinColumn(name = "invoice_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "branch_id", referencedColumnName = "id"))
private Branch billedTo;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "shipped_to_invoices", joinColumns = @JoinColumn(name = "invoice_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "branch_id", referencedColumnName = "id"))
private Branch shippedTo;
}
我应该能够找到