2017-02-07 111 views
1

以下映射給人多對一映射在Hibernate中

外鍵闖民宅db.KarateInvoice錯誤從db.KarateInvoiceDetail 有錯誤的數列。應爲1

發票實體:

@Id 
@Column(name = "id") 
private long      id; 
@OneToOne 
@JoinColumn(name = "companyid") 
@Id 
private Company     company; 
@Id 
private short      fiscalYear; 
@OneToMany(mappedBy = "karateInvoiceDetails") 
private List<KarateInvoiceDetail> karateInvoiceDetails; 

發票詳情:

@Id 
private short   seqNo; 
@ManyToOne 
@JoinColumns({ @JoinColumn(name = "karateInvoiceId"), 
     @JoinColumn(name = "karateInvoiceCompanyId"), 
     @JoinColumn(name = "karateInvoiceFiscalYear") }) 
private KarateInvoice invoice; 
@Id 
@OneToOne 
@JoinColumns({ @JoinColumn(name = "studentId"), 
     @JoinColumn(name = "studentCompanyId") }) 
private KarateStudent student; 

公司實體:

@Id 
private long  id; 

想法是有一個Invoice表的複合(id,fiscalyear和companyId)和具有(seqNo,InvoiceId,InvoiceFiscalYear和InvoiceCompanyId)組合鍵的。

+1

您正在使用什麼版本的Hibernate的?我只是測試了5.2.7上的映射,我沒有看到這是有問題的。 – Naros

+0

我正在使用休眠5.1 – Cybermonk

回答

1

我想你應該明確地引用在@JoinColumn註釋發票列:

@ManyToOne 
@JoinColumns({ @JoinColumn(name = "karateInvoiceId" 
        , referencedColumnName="id"), 
     @JoinColumn(name = "karateInvoiceCompanyId" 
       , referencedColumnName="companyId"), 
     @JoinColumn(name = "karateInvoiceFiscalYear" 
       , referencedColumnName="fiscalYear") }) 
private KarateInvoice invoice; 
+0

我認爲這應該工作。將測試它並接受答案。 – Cybermonk

+0

它沒有工作:/ – Cybermonk

+0

虐待稍後做一些更多的測試。錯誤是否一樣? –