Hibernate version: 3.0
In my current version of my software I have two classes Resource and Activity. The Resource class has a set of Activities and the Activity class has a set of Resources. In hibernate these are set up as many-to-many relationships.
In the next version of the software, I want to extend this Resource-Activity relationship to have a strength associated with it. To support this I have created a new class called Relationship. The hibernate definition of this is below:
Code:
<class name="cams.cmap.data.Relationship" table="activityresourcerelations">
<composite-id name="relationship_id" class="cams.cmap.data.RelationshipId">
<key-property name="activity" column="activity_id"/>
<key-property name="resource" column="resource_id"/>
</composite-id>
<many-to-one name="activity" class="cams.cmap.data.Activity" column="activity_id"
not-null="true" fetch="join" insert="false" update="false"/>
<many-to-one name="resource" class="cams.cmap.data.Resource" column="resource_id"
not-null="true" fetch="join" insert="false" update="false"/>
<property name="strength" not-null="true"/>
</class>
As you can see it has a composite key of activity_id and resource_id, and a strength property.
So, my next step was to change my Resource class to have a set of Relationships (instead of activities) and my Activity class to have a set of Relationships (instead of resources).
My problem comes when I try to define this in Hibernate. Below is what I have attempted (many other versions have also been tried...). Can anyone tell me what it should to be?
Code:
<class name="uk.ac.dundee.cams.cmap.data.Activity">
<id name="id" column="activity_id">
<generator class="increment"/>
</id>
<property name="description"/>
<set name="resourceRelationships" table="activityresourcerelations" order-by="resource_id" lazy="true" cascade="save-update">
<key column="activity_id"/>
<many-to-many class="cams.cmap.data.Relationship"/>
</set>
<set name="outcomes" table="ActivityOutcome" order-by="outcome_id" lazy="true" cascade="save-update">
<key column="activity_id"/>
<many-to-many column="outcome_id" class="cams.cmap.data.Outcome"/>
</set>
<many-to-one name="module" class="cams.cmap.data.Module" column="module_id" not-null="true"/>
</class>
Perhaps it is a bad design and my thought process is being clouded by the original design, or perhaps you have come accross a design pattern which might better suit what I am trying to do?
Any tips/ideas appreciated,
Nadia