-->
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.  [ 4 posts ] 
Author Message
 Post subject: many-to-many mapping question
PostPosted: Mon Jun 21, 2004 8:58 am 
Beginner
Beginner

Joined: Tue Mar 02, 2004 1:12 pm
Posts: 25
Location: Newcastle Upon Tyne
Hi

I am trying to model an association between two entities which will have a many-to-many mapping. But this association has certain properties of its own. Say I have a Person object and an Organization object - and the association (AffiliationEpisode) is actually a bridge between Person and Organization, with its own properties. I am following the suggestions posted in earlier similar topics and the hibernate FAQs - that is to model it as a composite element.

Peson mapping:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="uk.org.mygrid.infomodel.Person" table="person">
      <id name="LSID" type="java.lang.String" column="person_id" length="80" unsaved-value="null">
         <generator class="assigned"/>
      </id>
      <property name="firstName" type="java.lang.String" column="fName" not-null="true" length="20"/>
      <property name="lastName" type="java.lang.String" column="lName" not-null="true" length="30"/>
      <property name="x509DN" type="java.lang.String" column="x509dn" not-null="true" length="50"/>
...
      <!-- bi-directional many-to-many association to Organization (association class AffiliationEpisode) -->
      <array name="affiliation" table="affiliationepisode" cascade="all">
         <key>
            <column name="person_id" length="80"/>
         </key>
         <index column="person_ind"/>
         <composite-element class="uk.org.mygrid.infomodel.AffiliationEpisode">
            <property name="affiliationLSID" type="java.lang.String">
               <column name="affiliationlsid" index="by_last_first" length="80" not-null="true"/>
            </property>
            <property name="startDate" type="java.sql.Date"/>
            <property name="endDate" type="java.sql.Date"/>
            <property name="status" type="java.lang.String" length="20"/>
            <property name="description" type="java.lang.String" length="80"/>
            <many-to-one name="organization" class="uk.org.mygrid.infomodel.Organization"/>
         </composite-element>
      </array>
...


Now as per this, I'll have a reference to the Organization in the Affiliation class - but not the other way. But, I need a relation where I can get the Affiliation from the Organization class - a bidirectional one. Is it possible to do this through the composite element mapping?

Regards
Arijit


Top
 Profile  
 
 Post subject: i am having this problem too
PostPosted: Wed Jun 23, 2004 11:05 am 
Newbie

Joined: Tue Jun 22, 2004 4:36 am
Posts: 3
Did you find a solution for your problem?

I have also two tables with an association, which has additional properties.
I dont know how to make the m:n relation mapping bi-directional.

Lg,
Tom


Top
 Profile  
 
 Post subject: Re: i am having this problem too
PostPosted: Wed Jun 23, 2004 11:10 am 
Beginner
Beginner

Joined: Tue Mar 02, 2004 1:12 pm
Posts: 25
Location: Newcastle Upon Tyne
Thomas wrote:
Did you find a solution for your problem?

I have also two tables with an association, which has additional properties.
I dont know how to make the m:n relation mapping bi-directional.

Lg,
Tom


Hi

Sorry, I didn't get any direct response yet. But I was searching the older topics and in one of them, there was a suggestion to map these association classes as entities. I have done that for now - but if I get a better solution I will change.

Cheers
Arijit


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:04 pm 
Regular
Regular

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
I am also trying to solve this problem. Can someone please post the "best" solution for this scenario?

Thanks,

Ted


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

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.