1

The following mapping is giving an error of

A Foreign key refering db.KarateInvoice from db.KarateInvoiceDetail has the wrong number of column. should be 1

Invoice Entity:

@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; 

Invoice Detail:

@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; 

Company Entity:

@Id private long id; 

Idea is to have an Invoice table with a composite of (id, fiscalyear, and companyId) and InvoiceDetail with a composite key of (seqNo, InvoiceId, InvoiceFiscalYear, and InvoiceCompanyId).

2
  • 1
    What version of Hibernate are you using? I just tested the mapping on 5.2.7 and I don't see this being problematic. Commented Feb 7, 2017 at 4:49
  • I'm using hibernate 5.1 Commented Feb 9, 2017 at 3:50

1 Answer 1

1

I think you should explicitly reference the Invoice columns on the @JoinColumn annotations:

@ManyToOne @JoinColumns({ @JoinColumn(name = "karateInvoiceId" , referencedColumnName="id"), @JoinColumn(name = "karateInvoiceCompanyId" , referencedColumnName="companyId"), @JoinColumn(name = "karateInvoiceFiscalYear" , referencedColumnName="fiscalYear") }) private KarateInvoice invoice; 
Sign up to request clarification or add additional context in comments.

4 Comments

I think this should work. Will test it and accept the answer if it does.
ill do some more tests later. IS the error the same?
One crucial thing.. please add the DDL statements for the tables in question.. this might shed some light on things
Will do that. It says here that I should use IdClass or embedded id. Will try that too.. stackoverflow.com/questions/13032948/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.