views:

27

answers:

1

Is this possible without mapping the join table to a domain entity?

For example if I have the following three tables, account and note are joined by the table account_note. Can i map a collection of notes to account class with a one to many mapping?

1   to   M  |  1    to  M

Account -> Account_Note -> Note

+1  A: 

You need to use a many-to-many element.

Example:

<class name="Account">
  <id .../>
  <bag name="Notes" table="Account_Note">
    <key column="AccountId"/>
    <many-to-many class="Note" column="NoteId"/>
  </bag>
</class>
Diego Mijelshon
Thanks, I found some forum posts about it on nhforge. I noticed you used a bag, I've been told by some to always use bags, do you?
wdrone
I used bag as an example, but you can use whatever fits your domain (bag, set, list...)
Diego Mijelshon