0
votes

i have a collection in the mapping:

<bag name="Values" cascade="all-delete-orphan" lazy="false" inverse="true">
  <key column="[TemplateId]"/>
  <one-to-many class="MyNamespace.Value, MyLib"/>
</bag>

the Value object has a foreign key [TemplateId]. both entities has their generator set to "identity". when i call session.Save() for the parent Template object, the Value objects has their [TemplateId] (the foreign key) set to zero, so an SQL exception appears. how do i forse nhibernate to set the FK value for the child items to the value of the inserted parent object?

1

1 Answers

1
votes

i've managed it myself: the only thing i was needed to do is to design child object mapping and persistent the following way:

<many-to-one name="Template" class="MyNamespace.Template, MyLib"
                 column="[TemplateId]" not-null="true" />

so the child object has a reference to the parent instead of the parent's Id