春天JPA:主键是一个外键 - 这个类没有定义IdClass

问题描述 投票:0回答:1

我有一个主键,这也是在同一时间外键创建实体。不过,我得到以下错误“这个类没有定义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;
}
spring jpa primary-key
1个回答
0
投票

你缺少的构造函数包含字段采取主键@id(instrumentId:这是我的例子)。并缺少仪器类等和hashCode。

© www.soinside.com 2019 - 2024. All rights reserved.