Session still dirty even after refreshing of (only) changed entity
Description
Environment
Attachments
Activity
Fabio Maulo August 4, 2010 at 3:11 PM
Only as note if somebody will ask for Revert or Evict removing pending actions
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5166
was rejected.
The best way to avoid this kind of problems is avoiding the modification of the domain-entity when it is not really required.
Fabio Maulo August 4, 2010 at 2:37 PM
You are misunderstanding the meaning of Refresh... perhaps we should be more clear with our documentation.
Refresh mean refresh the state of a persistent instance and not Revert the state.
When you call session.Delete, or you remove an element from a collection, the entity come in a special state: becoming transient.
A becoming-transient-entity (pending-for-deletion) entity does not need a re-read from DB because it will be deleted at session-flush.
If you remove the deletion of AssociatedTestObject2 you will see that everything work fine.
What you are looking for is a Revert where any pending actions, over a specific object-graph, will be ignored and then any entity in the object-graph is "refreshed".
NH does not have a specific method to do it other than session.Evict and then session.Get.
Perhaps we can introduce it.
Fabio Maulo August 4, 2010 at 12:58 PM
why 2 attachs ?
m February 11, 2010 at 11:59 AM
For more information, also refer to this: http://groups.google.com/group/nhusers/browse_thread/thread/5fbd49c849d63986
m February 11, 2010 at 9:13 AM
Refactored test to correct jira entry number
When changing a collection in a one-to-many relation (like deleting an item), calling refresh afterwards doesn't set the session's state back to clean. IsDirty() still returns true. Cascade mode is set to "all" and no other entities are changed. Furthermore, calling Flush after Refresh throws an exception:
NHibernate.ObjectDeletedException : deleted object would be re-saved
by cascade (remove deleted object from associations)