В создаваемой системе Invoice
имеет billedFrom
, billedTo
и shippedTo
, каждый из которых является сущностью Branch
.Я не знаю, как определить @OneToMany
(если это действительно правильный способ отобразить это) сторону этих отношений в классе Branch.Вот что я сделал до сих пор
Подразделение
@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;
}
Я должен быть в состоянии выяснить
- Счета, выставленные в филиал (клиента)
- Счета, выставленные в моем филиале (компании)
- Счета, отправленные в филиал (клиента)