0

Using NHibernate, in my NUnit tests I might make a call such as session.Delete(_user) where _user is a persistent object.

My problem seems to be that unless I have this and any other updates included within a transaction, it never succeeds.

So,

CurrentSessionContext.Bind(GetHibernateSessionFactory().OpenSession());
ITransaction trans=session.BeginTransaction()
session.Delete(_user);
trans.Commit();
CurrentSessionContext.Unbind(GetHibernateSessionFactory())

works.

but,

CurrentSessionContext.Bind(GetHibernateSessionFactory().OpenSession());
session.Delete(_user);
CurrentSessionContext.Unbind(GetHibernateSessionFactory())

doesn't, yet there are no exceptions or problems being reported.

Any ideas?

Vicki
  • 668
  • 7
  • 21

1 Answers1

3

NHibernate will only send updates / inserts / deletes to the database, when the session is being flushed.

You can do that explicitly by calling Flush(), but you should also look at the configuration: you can specify the default flushing behaviour there as well.

Interesting reads:

NHibernate ISession Flush: Where and when to use it, and why? NHibernate Flush-- How it works?

Community
  • 1
  • 1
Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154