Hibernate说重复列INVOICE_ID的映射。但我无法理解这个例外。请帮忙 !! 我的发票课程如下:
@Entity
@Table(name="INVOICES")
public class Invoice {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="INVOICE_ID", nullable=false,insertable=false,updatable=false)
private Integer invoice_id;
@Column(name="Date_Created", nullable=false)
private Timestamp dateCreated;
@Column(name="DESCRIPTION")
private String description;
@Column(name="Total_Amount")
private Double totalAmount;
@Column(name="Tax_Amount")
private Double taxAmount;
@Column(name="Due_Date")
private Timestamp dueDate;
@Column(name="deleted")
private boolean deleted;
@OneToOne
@JoinColumn(name="Invoice_Item_Detail_id", nullable=false)
private InvoiceItemsDetails invoiceItemsDetails;
@OneToOne
@JoinColumn(name="ID", nullable=false)
private Client client;
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Timestamp dueDate) {
this.dueDate = dueDate;
}
/* public Integer getInvoice_id() {
return invoice_id;
}
public void setInvoice_id(Integer invoice_id) {
this.invoice_id = invoice_id;
}
*/
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Timestamp dateCreated) {
this.dateCreated = dateCreated;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(Double totalAmount) {
this.totalAmount = totalAmount;
}
public Double getTaxAmount() {
return taxAmount;
}
public void setTaxAmount(Double taxAmount) {
this.taxAmount = taxAmount;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
public InvoiceItemsDetails getInvoiceItemsDetails() {
return invoiceItemsDetails;
}
public void setInvoiceItemsDetails(InvoiceItemsDetails invoiceItemsDetails) {
this.invoiceItemsDetails = invoiceItemsDetails;
}
}
我在USERS表中使用了INVOICE_ID作为外键,如下所示:
@OneToMany
@JoinColumn(name="INVOICE_ID", nullable=false)
public Set<Invoice> getInvoices() {
return invoices;
}
答案 0 :(得分:1)
这种映射对我来说毫无意义。
表INVOICE(它的主键)的INVOICE_ID列如何作为USER.ID列的外键?
INVOICE中应该有一个USER_ID列,此列应该作为OneToMany关联的JoinColumn:
@OneToMany
@JoinColumn(name="USER_ID", nullable=false)
public Set<Invoice> getInvoices() {
return invoices;
}