bonjorno
bonjorno

Reputation: 211

Why isn't Nhibernate Interceptor called?

I used NHibernate 2.1.2, FluentNhibernate 1.1, and SQLite configured with In Memory (For unit testing purposes).

The purpose of the interceptor is to make proxy object returned by create criteria. I think I already registered the interceptor to the configuration correctly, but create criteria only returns the naked object instead of the proxied one. I tried to put a breakpoint on the interceptor Instantiate method but the breakpoint was not hit.

So my question is, how can I know whether my interceptor is already setup correctly or not? Could I debug using logging?

I'm having a problem with using configuration in Visual Studio unit testing.

Upvotes: 3

Views: 1280

Answers (1)

bonjorno
bonjorno

Reputation: 211

OK, i spent 12 hours because of trivial problem.

Interceptor didn't work for ISession.Get

here is what i have been mistaken

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 work fine after i decided to just leave it and start to write unit test for GetUsers method which is using Criteria API.

FYI if you interesting on NHibernate interceptor, i found it here.

Upvotes: 2

Related Questions