1

我正在尝试与引用 3 个表的 3 个键的复合主键建立三元关联:REPORT、SCANNER 和 RISK,我尝试使用下面的代码实现这一点,但我有一个只有 2 个键的复合键: riskId 和 reportId :

报告.java

@Entity
@Table(name="REPORT")
public class Report {
    @Id
    @NotNull
    @GeneratedValue  
    private int reportId;

    @Column
    private String reportName;

    @OneToMany
    @MapKeyJoinColumn
    Map<Risk, Scanner> risks = new HashMap<Risk, Scanner>();
}

扫描仪.java:

@Entity
@Table(name="SCANNER")
public class Scanner{
    @Id
    @NotNull
    @GeneratedValue  
    private int scannerId;

    @Column
    private String scannerName; 
}

风险.java:

@Entity
@Table(name="RISK")
public class Risk {
    @Id
    @NotNull
    @GeneratedValue
    private int riskId;

    @Column
    private String issueName;
}

那么如何实现具有 3 个键的复合主键呢?

4

0 回答 0