您将如何仅使用 FOO_ID 将 bar 对象列表映射到 Foo 对象?
@Entity
@Table(name="FOO")
class Foo {
@EmbeddedId
private FooPK primaryKey;
@OneToMany
@JoinColumn(name="FOO_ID", referencedColumnName="FOO_ID") //does not work
private List<Bar> bars;
}
@Embeddable
class FooPK {
@Column(name="FOO_ID")
private String id;
@Column(name="FOO_SUB_ID")
private String subId;
}
@Entity
@Table(name="BAR")
class Bar {
@EmbeddedId
private BarPK primaryKey;
//other attributes and methods
}
@Embeddable
class BarPK {
@Column(name="FOO_ID")
private String id;
@Column(name="BAR_ID")
private String barId;
@Column(name="BAR_SUB_ID")
private String barSubId;
}
我试过:@JoinColumn(如上)和@JoinTable 在另一个包含 FOO_ID 作为主键的表上。两者都不起作用。