spring - Spring JPA:主键是外键 - 此类未定义 IdClass
问题描述
我正在创建一个主键同时也是外键的实体。但是,我收到以下错误“此类未定义 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 :这是我的示例),并且在 Instrument 类中缺少 equal 和 hashCode。
推荐阅读
- loops - 有没有办法摆脱这个循环?(淡入淡出和 LED 的问题)
- css - 如何在悬停时进行特定的边框底部过渡/动画?
- javascript - 在运行函数之前异步/等待返回承诺
- python - Python烧瓶视频流无法处理多个客户端
- javascript - 将日期格式从 0000-00-00T00:00:00 更改为 mm/dd/yyyy
- node.js - 无法在 ATOM 上加载 atom-beautify
- mysql - MYSQL Union 将 0 和 False 初始化为 bigint
- javascript - 使用嵌套在其他 SVG 内的空 SVG 时不会触发 OnClick
- java - JavaFX css网格不一致
- javascript - 如何在隐藏的 DIV 中保持 CSS 动画播放