We recently upgraded to NHibernate 3.2. We have a number of integration tests which "test" that queries are properly generated. These tests execute against an empty database which is built from our migration scripts on each test run. Essentially all we're doing is making sure that NHibernate generates valid queries based on the db schema.
Many of the queries rely on proxy entities for querying. For instance. Foo has a reference to Bar. We have the Id of an instance of Bar. Using ICriteria, we query for Foo by passing a proxy Bar which is created by ISession.Load<Bar>(id);. For our tests, this works just fine because we can use a randomly generated Id just to see if the query is properly generated.
However, since upgrading to NHibernate 3.2, tests which rely on this are failing. But only if we include the code "HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();", which we leave on in our debug builds.
Here is an example stack trace (I've left out the lines from our application code, so it starts with the call into NHibernate):
at NHibernate.Impl.SessionFactoryImpl.DefaultEntityNotFoundDelegate.HandleEntityNotFound(String entityName, Object id) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs:line 84
at NHibernate.Proxy.AbstractLazyInitializer.CheckTargetState() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Proxy\AbstractLazyInitializer.cs:line 259
at NHibernate.Proxy.AbstractLazyInitializer.Initialize() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Proxy\AbstractLazyInitializer.cs:line 127
at NHibernate.Proxy.DefaultLazyInitializer.Intercept(InvocationInfo info) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Proxy\DefaultLazyInitializer.cs:line 32
at ProviderOrganizationProxy.ToString()
at System.String.Concat(Object arg0, Object arg1, Object arg2)
at NHibernate.Criterion.SimpleExpression.ToString() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Criterion\SimpleExpression.cs:line 164
at NHibernate.Impl.CriteriaImpl.CriterionEntry.ToString() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 970
at NHibernate.Impl.CriteriaImpl.ToString() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 323
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at System.String.Format(String format, Object[] args)
at HibernatingRhinos.Profiler.Appender.NHibernate3Logger.ProfilerLogger.DebugFormat(String format, Object[] args)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateCriteriaSQLAliasMap() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Criteria\CriteriaQueryTranslator.cs:line 503
at NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor(ISessionFactoryImplementor factory, CriteriaImpl criteria, String rootEntityName, String rootSQLAlias) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Criteria\CriteriaQueryTranslator.cs:line 74
at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Criteria\CriteriaLoader.cs:line 37
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1928
at NHibernate.Impl.CriteriaImpl.List(IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 265
at NHibernate.Impl.CriteriaImpl.List[T]() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 276
From this it appears that the Profiler is trying to effectively ToString() the proxy object which forces it to load.
It also appears that this might be the result of the new internal proxy factory in 3.2. We previously used Castle, which worked fine. I suppose the new implementation is forcing the entity to load.
So even though I'm getting this error, I believe there are still issues where using the Profiler is definitely causing extra database reads because of the new proxy implementation.