Hi, I've got a problem with a parent / child relation, with the child having a composite-id. I use NHibernate 2.1 on SQL Server 2005.
Here are the mappings for my 2 entities :
The parent :
Code:
<class name="QuestionnaireTable" table="QUESTTABLE">
<id name="Id">
<column name="QTA_ID" sql-type="numeric" length="9" />
<generator class= "identity" />
</id>
<property name="Code" column="QTA_CODE" type="string" length="15"/>
[...]
<bag name="QuestionnaireStructureCols" table="QUESTSTRUCTCOL" lazy="false" cascade="all-delete-orphan" >
<key>
<column name="QTA_ID" not-null="true" />
</key>
<one-to-many class="QuestionnaireStructureCol" />
</bag>
</class>
Child
Code:
<class name="QuestionnaireStructureCol" table="QUESTSTRUCTCOL">
<composite-id unsaved-value="any" >
<key-property name="QuestionnaireTableId" column="QTA_ID" type="long" />
<key-property name="ColNum" column="QSC_COL_NUM" type="long"/>
</composite-id>
<property name="Width" column="QSC_WIDTH" type="long" />
</class>
I try to create a new object, filled with one element :
QuestionnaireTable q = new QuestionnaireTable();
q.QuestionnaireStructureCol = new List();
QuestionnaireStructureRow r = new QuestionnaireStructureRow();
r.ColNum = 1;
q.Add(r);
session.SaveOrUpdate(q);
I've got an error on the SaveOrUpdate, because the field "QTA_ID", which is part of the foreign key and the id of the child, is not updated..
For example, at first, all my objects have a "QTA_ID" equals to 0.
after SaveOrUpdate, my QuestionnaireTable has a QTA_ID = 90, but my object "QuestionnaireStructureRow" stay with a QTA_ID = 0, and the generated SQL crash
INSERT INTO QUEST_STRUCTURE_COL (QTA_ID, QSC_WIDTH, QSC_COL_NUM) VALUES (?, ?, ?, ?) --> QTA_ID is binded to 0.
Did I miss something ? I can't figure out what's the problem, thanxs in advance for any help !