Roll back changes to object if invalid

Posted by hhravn on Stack Overflow See other posts from Stack Overflow or by hhravn
Published on 2010-06-09T09:36:49Z Indexed on 2010/06/09 10:12 UTC
Read the original article Hit count: 115

Filed under:

How do i roll back changes to an attached object in nhibernate? We have a validation before update/save (example simplified)..

var setting = Get("key")
setting.Value = "helo" //for whatever reason, this particular 
                       //setting cannot have its value saved to the database
...
Verify(setting);       //throws
base.Update(setting);

but since the object is attached, any changes already happened in the session, even if the validation throws, and never reaches Update. What is the proper way to handle this?

© Stack Overflow or respective owner

Related posts about nhibernate