As discussed in hibernate docs (7.5.3. many to many in
http://www.hibernate.org/hib_docs/refer ... tions.html) the mapping for a bidirectional many-to-many table is :
<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
<set name="addresses" table="PersonAddress">
<key column="personId"/>
<many-to-many column="addressId"
class="Address"/>
</set>
</class>
<class name="Address">
<id name="id" column="addressId">
<generator class="native"/>
</id>
<set name="people" inverse="true" table="PersonAddress">
<key column="addressId"/>
<many-to-many column="personId"
class="Person"/>
</set>
</class>
where PersonAddress table holds the relationship bet Person and Addres using foriegn keys. It is with the assumption that table definitions are something like :
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null, primary key (personId, addressId) )
create table Address ( addressId bigint not null primary key )
Now, my question would be, how do I create my mapping if I have the following table definition for PersonAddress?
create table PersonAddress ( personAddressId bigint not null, personId bigint not null, addressId bigint not null, other string not null, primary key (personAddressId) )
How do I set values to columns "personAddressId" and "other" such that when I save the Person or Address data, corresponding entries will be created in the PersonAddress.
Ive tried searching for samples of such case but all I can see are examples that only contain 2 foreign keys in link table of a many-to-many mapping(such as the one on top).