Hibernate version:
3.0
Mapping documents:
I have two classes: Activity and Resource
At the moment these two have a many-to-many relationship, each Activity has a set of Resources and each Resource has a set of Activities:
Code:
<class name="data.Resource" table="resource" >
<id name="id" column="resource_id">
<generator class="increment"/>
</id>
<set name="activities" table="ResourceActivity" order-by="activity_id" lazy="true" cascade="save-update">
<key column="resource_id"/>
<many-to-many column="activity_id" class="data.Activity"/>
</set>
</class>
And the same again for Activity, but with a set of resources.
I now want to record the strength of the relationship, such as weak or strong. I have created a new class called Relationship which has three properties, an activity, resource and strength. My resources' set of activities is now a set of relationships as is my activities' set of resources. How do I define this in my hbm.xml file though as I cannot do as follows?
Code:
<class name="data.Activity">
<id name="id" column="activity_id">
<generator class="increment"/>
</id>
<set name="resources" table="ResourceActivity" order-by="resource_id" lazy="true" cascade="save-update">
<key column="activity_id"/>
<many-to-one name="strength"/> !!! not allowed !!!
<many-to-many column="resource_id" class="data.Resource"/>
</set>
</class>
I would like my rel table to look along the lines of:
Code:
| activity_id | resource_id | strength |
| 5 | 6 | 1 |
| 7 | 8 | 2 |
... etc.
Name and version of the database you are using:
Oracle 10