I have the following Nhibernate XML file, edited to the core bits:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="TTP.DAO" namespace="TTP.DAO" xmlns="urn:nhibernate-mapping-2.2">
<class name="InitialProcessSetup" table="InitialProcessSetup" lazy="true" >
<id name="SetupID" column="setupID" unsaved-value="0" type="System.Int32">
<generator class="identity"/>
</id>
<property name="DateCreated" column="DateCreated" />
<many-to-one class="StoredUser" name="CreatedBy" column="CreatedBy" cascade="all-delete-orphan" not-null="true"/>
<property name="OriginalDeadline" column="Deadline" />
<property name="Detail" column="Detail" />
<bag name="Subjects" table="InitialProcessSetupRatingSubject" inverse="true" cascade="all-delete-orphan">
<key column="SetupId" not-null="true" />
<many-to-many column="SubjectStoredUserId" class="StoredUser" />
</bag>
<bag name="Reviewers" table="InitialProcessSetupReviewer" cascade="all-delete-orphan">
<key column="SetupId" not-null="true" />
<many-to-many column="ReviewerStoredUserId" class="StoredUser" />
</bag>
<bag name="Invitations" cascade="all-delete-orphan">
<key column="Setup" not-null="true"/>
<one-to-many class="ProcessInvitation" />
</bag>
</class>
I populate a new instance of the class indicated in the above mapping and save via GenericDAO().SaveOrUpdate(setup); and it saves the main object details but does not store the bit.
On the class Subjects is defined as a virtual property that returns IList-StoredUser. The class constructor sets this property to a new List-StoredUser-().
The table indicated by the Subjects bag element is a pure mapping table that is it has a SetupID and StoredUserID column and that's it.
I add using a StoredUser to my derived StoredUserDAO() to the Subjects lists before saving. After the call to SaveOrUpdate() I also call Flush() as well.
In my database (SQL Server 2008R2) The main setup data is saved and the stored user I added to the Subjects list property is also saved it's just the mapping table does not get the setupID/StoredUserID added.
I'm a bit of a noob with Nhibernate and this is an existing project. Any help ideas on what is wrong would be most appreciated.