I think the issue could be that you are trying to continue to use the Session once you have performed a rollback and/or commit.
Typically I believe the best-practices for NHibernate (and other persistence frameworks) is to...
start a session
read in/register persistent objects within the session
-- do work (which may or may not mess with the persistent objects)--
either rollback or commit the session
dispose of the session
I would suggest you download the help file for NHibernate and read the
Transactions and Concurrency section to get a better understanding of how NHibernate manages Transactions and session state.
This example comes from the documentation
Code:
// foo is an instance loaded by a previous Session
foo.Property = "bar";
session = factory.OpenSession();
transaction = session.BeginTransaction();
session.SaveOrUpdate(foo);
session.Flush();
transaction.Commit();
session.Close();
In my applications I use a lightweight disposable wrapper around my calls to the NHibernate framework. On dispose, my wrapper performs a rollback (if Commit was not called) and the session is closed.
This this lightweight wrapper will throw an exception if I attempt to continue to use a session after I've either commited or rolledback.
My code would then look like:
Code:
using (IDataAccessSession session = DataAccessSessionFactory.Instance.Begin(Databases.MyDb))
{
Counterparty counterparty = GetCounterparty(session, toUpdate.Name);
counterparty.Name = "-updated";
session.Update(counterparty);
session.Complete();
}
Hope this helps
-Greg