-->
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: bidirectional many - to many relationships
PostPosted: Thu Jul 27, 2006 3:23 pm 
Newbie

Joined: Thu Jul 27, 2006 2:04 pm
Posts: 4
hello,

I am not clear on how to map this bidirectinal many - to many relationship

We have 3 tables

1. Person (id, name, adddress, age etc)
2. Category( catName, catCode etc)
3. Catmember(id,fk:id, fk:catCode, lastUpdateDate, Start Date etc)

SO catmember is like ajoin table but with extra fields.
the mapping we have is as follows
in
Person.hbm.xml
Code:
<set name ="categories" inverse="true" cascade="all" table="CatMember">
   <key column="ID" not-null ="true"/>
   <one-to-many class="CatMember"/>
</set>

in Category.hbm.xml
Code:
<set name ="members" inverse="true" cascade="all" table="CatMember">
   <key column="catCode" not-null ="true"/>
   <one-to-many class="Person"/>
</set>

the entire CatMember.hbm.xml
Code:
<hibernate-mapping package="com.myapp.domain">
   <class name="CatMember" table="CatMember">
      <id name="id" column="CM_ID" type="long" access="field">
         <generator class="increment" />
      </id>
      <many-to-one name="member" column="ID"/>
      <many-to-one name="category" column="CatCODE"/>
      <property name="startDate" column="CM_START_DATE" type="date"/>
      <property name="expireDate" column="CM_EXPIRE_DATE" type="date"/>
      <property name="lastUpdateDate" column="CM_LAST_UPDATE_DATE" type="date"/>
   </class>
</hibernate-mapping>

When we try to remove a category from a person it doesnot remove it from the catMember set. I know it has something to do with cascade attribute in the set property.

Any help would be greatly appreciated.

Thanks

Somesh
Code:
Code:


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.