0
votes

I seem to miss something here :

I have an application that uses a session per application method and using lazy loading.

I've set the session FlushMode.Commit and it seems that NHibernate still auto saves my dirty objects to the DB (SQLCe) although I never begin a transaction and commit it.

can anyone tell me what am I doing wrong ?

some of my code :

    public Repository(ISessionProvider sessionProvider)
    {
        _sessionProvider = sessionProvider;
        _session = _sessionProvider.OpenSession();
        _session.FlushMode = FlushMode.Commit;
    }

    public IList<T> GetAll<T>() where T : class
    {
        var criteria = _session.CreateCriteria<T>();
        var list = criteria.List<T>();
        return list;
    }
1
Implicit transactions are created if you do not create one by code as one would expect they are also auto committed. Use FlushMode.Never if you do not need this behavior. - Andreas
also note that the (n)hibernate team discourages the use of session per application - Firo
OK, I guess the best thing here to do is to change the way I work with the session and make it a better practice with NH. thanks :) - Builder Bob

1 Answers

0
votes

It seems that I had another thread that was flushing the same session while I was creating a dirty object in my UI, I guess it was just a bug in my application.

works Great now, still using a session per application since I need the Lazy feature.