Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate mapping child collection and embedded instance of child
    primarykey
    data
    text
    <p>I'm trying to figure what's the correct way to map the following parent child relationship. I have a parent class which contains child objects. However, the parent also has a pointer to an instance of one of the children (the PrimaryChild)</p> <pre><code>Class Parent Public Property Id As Integer? Public Property PrimaryChild As Child Public Property Children As IList(Of Child) End Class Public Class Child Public Property Id As Integer? Public MyParent As Parent End Class </code></pre> <p>Usage is something like</p> <pre><code>Dim ch As New Child Dim par as New Parent ch.MyParent = par par.Children.Add(ch) par.PrimaryChild = ch Session.SaveOrUpdate(par) </code></pre> <p>However, when I do this, the PrimaryChild is shown as being a null or transient value. I have set cascade="all" on the Children collection.</p> <p>Any ideas what I'm doing wrong?</p> <p><strong>Update 1</strong></p> <p>Added Mappings</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"&gt; &lt;class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Parent" table="Parents"&gt; &lt;id name="Id" type="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="ID" /&gt; &lt;/id&gt; &lt;set access="nosetter.camelcase-underscore" cascade="all-delete-orphan" inverse="true" name="Children" mutable="true"&gt; &lt;key&gt; &lt;column name="ParentID" /&gt; &lt;/key&gt; &lt;one-to-many class="Child" /&gt; &lt;/set&gt; &lt;many-to-one cascade="save-update" class="Child" name="PrimaryChild"&gt; &lt;column name="PrimaryChildID" not-null="true" /&gt; &lt;/many-to-one&gt; &lt;many-to-one cascade="save-update" class="Child" name="SecondaryChild"&gt; &lt;column name="SecondaryChildID" not-null="true" /&gt; &lt;/many-to-one&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"&gt; &lt;class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Child" table="Child"&gt; &lt;id name="Id" type="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="ID" /&gt; &lt;/id&gt; &lt;many-to-one class="Parent" name="Parent"&gt; &lt;column name="ParentID" not-null="true" /&gt; &lt;/many-to-one&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload