如何在 2 个类之间many-to-many
建立关系?以下分别是和的POJO。Person
Address
Person
Address
人 :
public class Person {
private int personID;
private String name;
private Person person;
private List addressList;
public List getAddressList() {
return addressList;
}
public void setAddressList(List addressList) {
this.addressList = addressList;
}
public int getPersonID() {
return personID;
}
public void setPersonID(int personID) {
this.personID = personID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
地址 :
public class Address {
private int addressID;
private String address;
private Person person;
public int getAddressID() {
return addressID;
}
public void setAddressID(int addressID) {
this.addressID = addressID;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
我试图定义的关系是A person can have many addresses and one address can belong to many people
。我无法在mapping xml
. 这是我迄今为止能够做到的。
<hibernate-mapping>
<class name="pojo.Person" table="person">
<id name="personID" column="p_id">
<generator class="increment" />
</id>
<property name="name" column="p_name" />
<list name="addressList" table="address">
<key column="a_id" />
<!-- DEFINE MANY TO MANY --!>
</list>
</class>
<class name="pojo.Address" table="address">
<id name="addressID" column="a_id">
<generator class="" />
</id>
<property name="address" />
</class>
</hibernate-mapping>
如何定义many to many
这两个类之间的关系?