我有一个主键,这也是在同一时间外键创建实体。不过,我得到以下错误“这个类没有定义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;
}
你缺少的构造函数包含字段采取主键@id(instrumentId:这是我的例子)。并缺少仪器类等和hashCode。