我们尝试了梅尔的建议,但未能成功。
换句话说,我们有OneToMany
关系:
开Student
:
protected List<AddressStudentAssociation> addresses;
开Address
:
protected List<AddressStudentAssociation> students;
并继续AddressStudentAssociation
:
@ManyToOne
@PrimaryKeyJoinColumn(name="STUDENTID", referencedColumnName="id")
private Student student;
@ManyToOne
@PrimaryKeyJoinColumn(name="ADDRESSID", referencedColumnName="id")
private Address address;
最后,在内部Student
有public Address getHomeAddress()
一个遍历addresses
列表并返回正确地址的地址。我们还必须使用注释来使其起作用。一般而言,它不是最佳方法,但是它可以工作,并且我们已经花了太多时间试图使事情起作用。:|