使用Composite键作为JPA中的外键会出错

时间:2014-05-19 13:12:32

标签: java jpa persistence jpa-2.0

我在这个类中有两个复合键( 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

}

在下面的类中,我有一个外部引用上述类中的一个复合键的键。 (模块和工具在此类中是复合的

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

现在问题是,当我尝试时,我无法将功能保留到数据库中,它会出现以下错误

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

有人知道原因吗?在此先感谢.....

0 个答案:

没有答案