Reputation: 8001
I've run into a problem with NH (v2.1.2) still thinking the session is dirty after I've refreshed the only entity that was modified in that session.
I have a parent->child relation set up with this mapping like this:
<set name="ChildItem" access="field.camelcase-underscore"
lazy="true"
cascade="save-update"
inverse="true">
<key column="PARENT_ITEM_KEY"/>
<one-to-many class="....ChildItem"/>
</set>
Here's the steps to reproduce the problem:
1 - Create new ChildItem and add it to the Parent's collection, but don't save it. Now session.IsDirty() returns true (as expected).
2 - Call session.Refresh(parent) to revert my change. After the refresh, the parent's collection now does not contain the new child item (as expected).
3 - Now session.IsDirty() returns true - although I'd expect false, as I've refreshed the only item that was modified.
Digging into the SessionImpl via the debugger, I can see that NH still has a pending Insert for the new ChildItem in it's ActionQueue.
Is it possible to return the session to an IsDirty()=false state in this scenario? I don't want to have to discard the whole session for this.
Any help much appreciated! Thanks!
Upvotes: 2
Views: 979
Reputation: 8001
Ok, so there doesn't seem to be an answer for this one. In the end it seems dropping the working session was the only way to discard the change. It meant a day or so of refactoring/retesting but it's up and running now.
Upvotes: 1
Reputation: 6865
You could try the following instead of Refresh()
. This is the usual workaround for problems with Refresh()
, but I don't know if it will help in your case.
session.Evict(parent);
session.Load(parent, parent.Id);
Upvotes: 0