0

I have two composite keys in this class (module, instrumentType)

@Entity
@Table(name = "aa_bank_instruments")
@IdClass(InstrumentsComposite.class)
public class Instruments extends Model {

  /**
   * 
   */
  private static final long serialVersionUID = -8401839630224674535L;

  @Id
  @JoinColumn(name = "module_id")
  @ManyToOne(cascade = CascadeType.ALL)
  private Module module;

  @Id
  @Column(name = "instrument_type")
  private String instrumentType;

  @Column(name = "descritpion")
  private String descritpion;

  //getters & setters

}

In the following class, I have a foreign a key referencing to ONE of a composite key in the above class. (module and instruments are composite in this class)

@Entity
@Table(name = "aa_bank_functions")
@IdClass(FunctionsComposite.class)
public class Functions extends Model{

  /**
   * 
   */
  private static final long serialVersionUID = -1162529578613327377L;

  @Id
  @Column(name = "function_id")
  private String functionId;

  @Id
  @JoinColumn(name = "instrument_type", referencedColumnName="instrument_type")
  @ManyToOne(cascade = CascadeType.ALL)
  private Instruments instruments;

  @Column(name = "description")
  private String description;
}

Now the problem is I can't persist Functions to the DB when I tries, It gives the following error

Caused by: org.hibernate.AnnotationException: A Foreign key refering com.fg.banking.model.Instruments from com.fg.banking.model.Functions has the wrong number of column. should be 2

Does anybody know the reason? Thanks in advance.....

Ravindu
  • 2,190
  • 7
  • 28
  • 46
  • 1
    Take a look to [this thread](http://stackoverflow.com/questions/3586493/hibernate-composite-key-problem-foreign-key-has-wrong-number-of-columns) seems to be the same problem. – Jens May 19 '14 at 13:20
  • @Jens Thanks man, the thread really helps – Ravindu May 20 '14 at 02:57

0 Answers0