我正在创建一个主键同时也是外键的实体。但是,我收到以下错误“此类未定义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;
}
答案 0 :(得分:0)
您缺少构造函数的字段包含主键@id。(instrumentId:这是我的示例),并且在Instrument类中缺少equal和hashCode。