Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate and adding new items with a composite collection to a child collection
    text
    copied!<p>I have three classes that pose a problem when trying to add a new child.</p> <p>They are:</p> <pre><code> User { List attributesGroup&gt; } AttributesGroup { attributesGroupId value } AttributesGroupId { attrName userId } </code></pre> <p>The mapping is: </p> <pre><code>&lt;class name="AlternativeUserAttributes" table="`AlternativeUserAttributes`" lazy="true"&gt; &lt;composite-id name="Id" class="Data.Entities.AlternativeUserAttributesId"&gt; &lt;key-property name="AttributeName" column="`attributeName`" type="string" /&gt; &lt;key-many-to-one name="User" class="Entities.User" column="`userId`" /&gt; &lt;/composite-id&gt; &lt;property name="AttributeValue" column="`attributeValue`" type="string" /&gt; &lt;many-to-one name="User" column="`userId`" cascade="none" not-null="true" /&gt; &lt;/class&gt; </code></pre> <p>I can remove items and class SaveUpdate on the user class without issue, however when I try to add an item to the collection via:</p> <pre><code> AlternativeUserAttributes aua = new AlternativeUserAttributes(); aua.Id = new AlternativeUserAttributesId(); aua.Id.AttributeName = name; aua.Id.User = curUser; aua.AttributeValue = value; aua.User = curUser; curUser.AlternativeUserAttributes.Add(aua); </code></pre> <p>I get an error about that the row count was expected to be 1 but was zero, and when I try to save only the AlternateUserAttributes as its self using Save, I get the this error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index</p> <p>Both attempts are yelding a INSERT for the new Item but i keep getting these errors. Is there anyone that can help?</p>
 

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