1

Resolved

NHibernate FlushMode issue.

description

Object is being persisted even when NHibernate's flushmode is set to commit only.
 
Test to reproduce:
[Test]
    public void ObjectPersistedWithoutTransactionCommit()
    {
        using (UnitOfWorkScope scope = new UnitOfWorkScope())
        {
            User user = GetValidUser();
            ISession session = NHibernateSetup.GetSession();
            session.FlushMode = FlushMode.Commit;
            IRepository<User> repository = new NCommon.Data.NHibernate.NHRepository<User>(session);
            repository.Add(user);
        }
    }
 
You will have a user record in your database at the end of this test. Since scope.Commit() was never called I don't think this is expected behavior.

comments

nephesh wrote Dec 26, 2008 at 3:00 AM

Ignore the above, this was due to my misunderstanding of how to inject the repositories into my services while also using the same ISession between the UoW and the repositories. That said, I haven't figured out a way to do this without editing the NCommon code. If we could get an example on how to do this I would appreciate it. For now I'm just using my edits.

Thanks

riteshrao wrote Feb 27, 2009 at 3:11 PM

See the sample web site in NCommon 0.3 release. That should provide a good example.

wrote Feb 27, 2009 at 3:11 PM

wrote Feb 14, 2013 at 12:28 AM

wrote May 16, 2013 at 4:29 AM

wrote May 16, 2013 at 4:29 AM

wrote Jun 14, 2013 at 8:26 AM