jpa同时休眠主键和外键与复合pk

scyqe7ek  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(425)

情境jpa hibernate:-我有表1和复合pk:
t1id1+t1id2-我有表2和pk:t2id和t2id=t1id1
我怎样才能绘制这个Map?我试过这个:

@Entity
public class Table1 {
    @EmbeddedId
    private Table1pk table1pk;

    @MapsId("t1id1")
    @ManyToOne
    @JoinColumn(name = "shared_id")
    private Table2 table2;

}

@Embeddable
public class Table1pk {

    @Column(name = "shared_id")
    private int t1id1;
    private String t1id2;
}

@Entity
public class Table2 {
    @Id
    @GeneratedValue
    @Column(name = "shared_id")
    private int t2id;

    @OneToMany
    List<Table1> table1rows;

}

我也试过这个:
远离的 @Embeddable 以及 @EmbeddedId 并替换为:

@Entity
@IdClass(Table1pk.class) 
public class Table1 {

    @Id
    private String t1id2;

    @Id
    @ManyToOne
    @JoinColumn(name = "shared_id")
    private Table2 table2;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题