nHibernate Self Join Mapping

Posted by kmoo01 on Stack Overflow See other posts from Stack Overflow or by kmoo01
Published on 2010-05-11T09:09:29Z Indexed on 2010/05/11 9:14 UTC
Read the original article Hit count: 386

Filed under:
|
|
|
|

Hi Guys,

This is probably incredibly simple, but I just cant see the wood for the trees at the moment.

For brevity, I would like to model a word object, that has related words to it (synonyms), In doing so I could have the following mappings:

<class name="Word" table="bs_word">
<id name="Id" column="WordId" type="Int32" unsaved-value="-1">
  <generator class="native">
    <param name="sequence"></param>
  </generator>
</id>

<property name="Key" column="word" type="String" length="50" />
<many-to-one name="SynonymGroup" class="BS.Core.Domain.Synonym, BS.Core" column="SynonymId"  lazy="false"/>


<class name="Synonym" table="bs_Synonym">
<id name="Id" column="SynonymId" type="Int32" unsaved-value="-1">
  <generator class="native">
    <param name="sequence"></param>
  </generator>
</id>
<property name="Alias" column="Alias" type="String" length="50" />
<bag name="Words" cascade="none" lazy="false" inverse="true">
  <key column="SynonymId" />
  <one-to-many class="Word"  />
</bag>

Mapping it like this would mean for a given word, I can access related words (synonyms) like this:

word.SynonymGroup.Words

However I would like to know if it is possible to map a bag of objects on an instance of a word object...if that makes sense, so I can access the related words like this:

word.Words

I've tried playing around with the map element, and composite elements, all to no avail - so I was wondering if some kind person could point me in the right direction?

ta, kmoo01

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about mapping