The issue should/could be in the <key>
mapping:
<bag name="Keywords" table="StatueKeyword" lazy="false">
<!-- <key> is representing column where current Statue ID should be searched
while the below one seems to be the ID column of the pairing table
so instead of this
<key column="IdStatueKeyword"/>
use this: -->
<key column="IdStatue"/>
<many-to-many class="Keyword" column="IdKeyword"/>
</bag>
Also check these:
- 6.3. Collections of Values and Many-To-Many Associations
- 23.2. Author/Work - documented example with
many-to-many
Small cite:
The foreign key from the collection table to the table of the owning class is declared using a
<key>
element.
Another tip, if you do have an ID column of the pairing table, you should try to use augmented feature:
Another cite from doc about idbag:
Note that the update performance of an
<idbag>
is much better than a regular<bag>
! NHibernate can locate individual rows efficiently and update or delete them individually, just like a list, map or set.
Finally, I (personally) would descourage you from using many-to-many
. My view is, that it is better to avoid it. See: 24. Best Practices (a cite:)
Don't use exotic association mappings.
Good usecases for a real many-to-many associations are rare. Most of the time you need additional information stored in the "link table". In this case, it is much better to use two one-to-many associations to an intermediate link class. In fact, we think that most associations are one-to-many and many-to-one, you should be careful when using any other association style and ask yourself if it is really neccessary.
Maybe later also check these: