Spring JPA:主键是外键-此类未定义IdClass

时间:2019-02-10 22:23:37

标签: spring jpa primary-key

我正在创建一个主键同时也是外键的实体。但是,我收到以下错误“此类未定义IdClass”。可能是什么问题?

班级报价

@Entity
@Data
@IdClass(Instrument.class)
public class Quote implements Serializable  {

    @Id
    @OneToOne
    @JoinColumn(name = "instrument")
    @NotNull
    private Instrument instrument;

    @NotNull
    private String time;

    @NotNull
    private double bid;

    @NotNull
    private double ask;

    @CreatedDate
    @Temporal(TIMESTAMP)
    @NotNull
    protected Date creationDate = new Date();

}

类乐器

@Entity
@Data
public class Instrument implements Serializable {

    @Id
    private String instrument;

    @NotNull
    private Currency currencyPrimary;

    @NotNull
    private Currency currencySecondary;
}

1 个答案:

答案 0 :(得分:0)

您缺少构造函数的字段包含主键@id。(instrumentId:这是我的示例),并且在Instrument类中缺少equal和hashCode。