Hi,
I am trying to model a camp ground, with Camp Sites adjacent to each other. It took me a little while to realise this is actually a many-to-many mapping. I amended my mappings and everything now seems fine, or at least acceptable. But is occurs to me that I really would like to read the mapping table transitively, that is, if site 5 is recorded as adjacent to site 10, then that mapping should act as also declaring 10 adjacent to 5.
Currently, my mapping file contains:
Code:
<hibernate-mapping>
<class
name="au.com.objectconsulting.camping.model.Site"
table="site"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<bag
name="adjacentSites"
table="adjacent_sites"
lazy="true"
inverse="false"
cascade="none"
>
<key
column="site_id"
/>
<many-to-many
class="au.com.objectconsulting.camping.model.Site"
column="adjacent_id"
outer-join="auto"
/>
</bag>
Which results in the table definition:
Code:
create table adjacent_sites (site_id BIGINT not null, adjacent_id BIGINT not null)
Which means each pair of adjactent sites should be recorded twice and enforged by coded businsess logic rules. Is there any way to read the mapping table both ways?
Regards
Peter Miller