Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# swilliam 3/23/2007 8:36 AM
Dear All

I'm getting some strange errors when deleting an item from a one to many relation. I have a basket and can quite happily add or update basket items to the basket's basket items ArrayList. I'm deleting items by removing them from the ArrayList then calling CommonDao.Save(basket).

The full message is:
SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.

Interestingly, this code works without errors when called via an NUnit test but not when used on the web so perhaps this is session related. The mapping for the Basket class is this:
bag name="BasketItemList" inverse="true" lazy="true" cascade="all-delete-orphan"

I'm new to NHibernate so I'm not really sure what I'm doing. Does anyone have any ideas?

Many thanks

Simon
# martijnb 3/25/2007 3:11 PM
Can you check with NHibernate logging what SQL statements are issued? You can do this by adding the following part to the log4net section in the config file:
<logger name="NHibernate.SQL">
    <level value="INFO" />
</logger>
# swilliam 3/28/2007 2:53 PM
Dear All

Interestingly, this problem was caused when adding a newly-created item to a persistent collection, removing it, then saving the collection's container object. NHibernate is trying to remove an item from the database with the id of "unsaved-value". Strangely, this doesn't happen when run as a unit test. I've worked around this by making sure than items are only removed after the previous changes are saved.

Simon