Why is Nhibernate Interceptor not called?

I used NHibernate 2.1.2, FluentNhibernate 1.1, and SQLite configured using In Memory (for testing purposes).

The purpose of the interceptor is to make the intermediary object returned using creation criteria. I think that I have already correctly registered the interceptor for the configuration, but creating criteria returns only a bare object instead of a proxy. I tried to set a breakpoint on the Interceptor Instantiate method, but the breakpoint was not removed.

So my question is: how can I find out if my interceptor is configured correctly or not? Can I debug log usage?

I had a problem using configuration in Visual Studio unit testing.

+3
source share
1 answer

OK, I spent 12 hours due to a trivial problem.

The interceptor did not work for ISession.Get

that's what i was wrong

public UserModel Save(UserModel user)
{
    UserModel result = null;
    using (ITransaction transaction = session.BeginTransaction())
    {
        var id = session.Save(user);
        //here i expect a proxied UserModel will returned
        result = session.Get<UserModel>(id);
        transaction.Commit();
    }
    return result;
}

I realized that my interceptor was working fine after I decided to just leave it and start writing unit test for a GetUsersmethod that uses the criteria API.

FYI, if you are interested in NHibernate interceptor, I found it here .

+2
source

Source: https://habr.com/ru/post/1761473/


All Articles