Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何创建与复合Id相关的PK类_Java_Jpa_Many To Many_Eclipselink - Fatal编程技术网

Java 如何创建与复合Id相关的PK类

Java 如何创建与复合Id相关的PK类,java,jpa,many-to-many,eclipselink,Java,Jpa,Many To Many,Eclipselink,我将实体A的Id更改为复合Id。实体B也有一个PK类,关系的一侧是实体A。我应该如何更改PK类代码?我应该使用IdClass而不是Id吗 public class BPK implements Serializable{ // I need to change this single Id to a composite Id to include 2 columns from Entity A instead of only one id attribute @Id

我将实体A的Id更改为复合Id。实体B也有一个PK类,关系的一侧是实体A。我应该如何更改PK类代码?我应该使用IdClass而不是Id吗

public class BPK implements Serializable{

    // I need to change this single Id to a composite Id to include 2 columns from Entity A instead of only one id attribute 
    @Id
    @Column(name = "aid")
    private Integer a;

    @Id
    @Column(name = "bid")
    private Integer b;

}
甲级PK

public class APK implements Serializable{

    @Id
    @Column(name = "id")
    private Integer id;

    @Id
    @Column(name = "project_mode")
    private Integer project;
 }
JPA中的主键类不需要注释,因为它们已经直接映射到实体中。派生ID是规范允许在主键中嵌套的位置,因为嵌套类总是向下钻取到基本类型(vs实体)

public class BPK implements Serializable{
    private APK a;
    private Integer b;

}