Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate: Criteria query slow in web app but fast in unit tests, why?
    primarykey
    data
    text
    <p>I am having a problem where a criteria query in NHibernate is executes in less then a second when I run it in a unit test, but when I try to run it from the context of my web application, it takes over a minute. Both are hitting the same database for the same data.</p> <p>My NHibernate mapping:</p> <pre><code>var properties = new Dictionary&lt;string, string&gt;(); var configuration = new Configuration(); properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); properties.Add("proxyfactory.factory_class", "NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate"); properties.Add("connection.release_mode", "on_close"); properties.Add("current_session_context_class", "web"); properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect"); properties.Add("connection.connection_string_name", "DBConnection"); configuration.Properties = properties; SessionFactory = configuration.BuildSessionFactory(); </code></pre> <p>The only difference in this mapping between tests and the web app is the current_session_context_class, where it is thread_static in tests, but that does not seem to be the problem.</p> <p>The criteria for the query:</p> <pre><code>var reports = Session.CreateCriteria&lt;Report&gt;() .SetFetchMode("Site", FetchMode.Join) .SetFetchMode("Actions", FetchMode.Join) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .Add(Subqueries.PropertyIn("Site", SiteCriteria.GetSitesForUserWithPermission(user, Permission.SomePermission)))) .List&lt;Report&gt;(); </code></pre> <p>I have tried using NH Profiler to help, but it did not offer any useful suggestions.</p> <p>edit: Looking further in nhprofiler, I see that in the test for example, the query duration is 1ms / 313ms (Database only / Total). But for the website it just took me 1ms / 43698ms. It seems that NHibernate is having a hard time mapping the actual objects.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload