-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-to-many relationship with properties
PostPosted: Tue Oct 10, 2006 11:18 am 
Newbie

Joined: Wed Jul 13, 2005 9:04 am
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.