2013-04-06 158 views
0

Hibernate说重复列INVOICE_ID的映射。但我无法理解这个例外。请帮忙 !! 低于我的发票类给出:org.hibernate.MappingException:实体映射中的重复列:Invoice列: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; 
     } 

    } 

我用INVOICE_ID作为USERS表的外键,如下所示:

@OneToMany 
    @JoinColumn(name="INVOICE_ID", nullable=false) 
    public Set<Invoice> getInvoices() { 
     return invoices; 
    } 

回答

1

这种映射是没有意义的我。

表INVOICE(它的主键)的INVOICE_ID列如何作为USER.ID列的外键?

应该有发票USER_ID列,此列应作为一个JoinColumn您的一对多关联关系:

@OneToMany 
@JoinColumn(name="USER_ID", nullable=false) 
public Set<Invoice> getInvoices() { 
    return invoices; 
} 
相关问题