asp.net - NHibernate: Criteria query slow in web app but fast in unit tests, why? -


i having problem criteria query in nhibernate executes in less second when run in unit test, when try run context of web application, takes on minute. both hitting same database same data.

my nhibernate mapping:

var properties = new dictionary<string, string>(); 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(); 

the difference in mapping between tests , web app current_session_context_class, thread_static in tests, not seem problem.

the criteria query:

var reports =   session.createcriteria<report>()         .setfetchmode("site", fetchmode.join)         .setfetchmode("actions", fetchmode.join)         .setresulttransformer(new distinctrootentityresulttransformer())         .add(subqueries.propertyin("site",             sitecriteria.getsitesforuserwithpermission(user, permission.somepermission))))         .list<report>(); 

i have tried using nh profiler help, did not offer useful suggestions.

edit: looking further in nhprofiler, see in test example, query duration 1ms / 313ms (database / total). website took me 1ms / 43698ms. seems nhibernate having hard time mapping actual objects.

the difference between unit tests , web app unit tests aren't logged. added our log4net.config:

<filter type="log4net.filter.levelrangefilter">     <levelmin value="warn" /> </filter> 

and problem went away.

it outputting lot of stuff this:

2011-07-21 13:07:17,479 debug [14] loadcontexts - attempting locate loading collection entry [collectionkey[actions#d6adfe87-a7d4-4821-bb10-4ef76fcf614d]] in result-set context 2011-07-21 13:07:17,481 debug [14] loadcontexts - collection [collectionkey[actions#d6adfe87-a7d4-4821-bb10-4ef76fcf614d]] not located in load context 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -