Geeks With Blogs
A Curious Mind #tastic

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

Posted on Wednesday, August 23, 2006 5:28 PM | Back to top


Comments on this post: NHibernate Issues

# re: NHibernate Issues
Requesting Gravatar...
Both ways are really bad performance wise.
What SQL statement does this generate?
Left by Ayende Rahien on Aug 23, 2006 5:46 PM

# re: NHibernate Issues
Requesting Gravatar...
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.
Left by Erik Lane on Aug 28, 2006 6:46 PM

# re: NHibernate Issues
Requesting Gravatar...
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
Left by Dru on Aug 28, 2006 6:50 PM

# re: NHibernate Issues
Requesting Gravatar...
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!
Left by Erik Lane on Aug 28, 2006 7:00 PM

# re: NHibernate Issues
Requesting Gravatar...
Thanks for the idea though. I will certainly be looking into it further.
Left by Dru on Aug 28, 2006 7:04 PM

# re: NHibernate Issues
Requesting Gravatar...
Hi everyone,

Did anyone find a solution for this problem??
Left by Let on Aug 27, 2007 10:45 AM

# re: NHibernate Issues
Requesting Gravatar...
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
Left by Jasper on Apr 30, 2008 8:14 PM

# re: NHibernate Issues
Requesting Gravatar...
I think I just removed the list support by the way and went back to a bag.
-d
Left by Dru Sellers on May 01, 2008 5:06 AM

Your comment:
 (will show your gravatar)


Copyright © Dru Sellers | Powered by: GeeksWithBlogs.net