A Curious Mind
#tastic

NHibernate Issues

Wednesday, August 23, 2006 5:28 PM

Arghhh, I am really starting to hate NHibernate List support. However, this is my problem and not NHibernate's. I just have to figure out how this is supposed to work.

I have a list collection

<list name="EmailNotifications"
      table="Rules_Notifications"
      access="nosetter.camelcase-underscore">
    <key column="OrganizationId" />
    <index column="Indexer" />
    <composite-element class="Cystem.Notification,Cystem">
        <property name="Email" type="String" />
        <property name="Language" type="Cystem.LanguageType,Cystem" />
    </composite-element>
</list>

However when I go to execute the following code I get an exception:

private void RemoveFromList(int index, IList list)
{
    if(list.Count > index)
    {
        object o = list[index];
        list.Remove(o); 
    }
}

//or

private void RemoveFromList(int index, IList list)
{
    if(list.Count > index)
    {
        list.RemoveAt(index);   
    }
}

I get the following error:

NHibernate.HibernateException: SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 2). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.
    at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
    at NHibernate.Collection.BasicCollectionPersister.DoUpdateRows(Object id, PersistentCollection collection, ISessionImplementor session)
    at NHibernate.Collection.AbstractCollectionPersister.UpdateRows(PersistentCollection collection, Object id, ISessionImplementor session)
    at NHibernate.Impl.ScheduledCollectionUpdate.Execute()
    at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
    at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
    at NHibernate.Impl.SessionImpl.Execute()
    at NHibernate.Impl.SessionImpl.Flush()
    at NHibernate.Transaction.AdoTransaction.Commit()

 

Any thoughts?

Dru


Feedback

# re: NHibernate Issues

Both ways are really bad performance wise.
What SQL statement does this generate? 8/23/2006 5:46 PM | Ayende Rahien

# re: NHibernate Issues

Dru,

Not sure if you got this one fixed or not but I'll share anyway. :-)

It looks like you are modifiying the list that you are working with. "Possible causes: the row was modified or deleted by another user." You cannot do that since it modifies the list and gets it out of sync. I'm not a NHibernate guy so I don't know what its doing but I've tried doing something like this in my own code.

What I had to do what create a new list, minus the item you want removed, and return it or set your instance variable to the new list.

This will resolve the conflict that you are seeing. 8/28/2006 6:46 PM | Erik Lane

# re: NHibernate Issues

Nope, not solved yet. Also, the error only appers when i want to remove an object that is not at the highest index.

items[0] <- Remove here ERROR
items[1] <- Remove here no error 8/28/2006 6:50 PM | Dru

# re: NHibernate Issues

Sorry my tip didn't help out. I'm pretty sure it has something to do with modifying that list while you still have a handle to it. Good luck! 8/28/2006 7:00 PM | Erik Lane

# re: NHibernate Issues

Thanks for the idea though. I will certainly be looking into it further. 8/28/2006 7:04 PM | Dru

# re: NHibernate Issues

Hi everyone,

Did anyone find a solution for this problem?? 8/27/2007 10:45 AM | Let

# re: NHibernate Issues

Do you have triggers associated with this table? If so this fixed up my variation of the same problem:

http://www.ayende.com/Blog/archive/2006/01/16/7954.aspx 4/30/2008 8:14 PM | Jasper

# re: NHibernate Issues

I think I just removed the list support by the way and went back to a bag.
-d 5/1/2008 5:06 AM | Dru Sellers

Post a comment





 

Please add 7 and 8 and type the answer here: