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