PDA

View Full Version : How do I configurate the OpenSessionInViewModule in my web apps?


Tommy_Shen
11-20-2006, 11:38 PM
hi all,
This question is aslo about the NHibernate.LazyInitializationException, I had put the config into my web.config below:
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule, Spring.Data.NHibernate"/>
</httpModules>

and, in my logfile I can see the OpenSessionInViewModule has worked:

2006-11-20 21:47:35,093 [3168] DEBUG Spring.Data.NHibernate.Support.OpenSessionInViewMo dule [(null)] - Opening single Hibernate Session in OpenSessionInViewFilter
2006-11-20 21:47:35,109 [3168] DEBUG Spring.Data.NHibernate.SessionFactoryUtils [(null)] - Opening Hibernate Session
2006-11-20 21:47:35,125 [3168] DEBUG NHibernate.Impl.SessionImpl [(null)] - opened session
2006-11-20 21:47:35,125 [3168] DEBUG Spring.Transaction.Support.TransactionSynchronizat ionManager [(null)] - Bound value [Spring.Data.NHibernate.SessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] to thread []

... ...
... ...
[
2006-11-20 21:47:37,546 [3168] DEBUG Spring.Transaction.Support.TransactionSynchronizat ionManager [(null)] - Retrieved value [Spring.Data.NHibernate.SessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] bound to thread []
2006-11-20 21:47:37,546 [3168] DEBUG Spring.Data.NHibernate.SessionFactoryUtils [(null)] - Opening Hibernate Session
2006-11-20 21:47:37,546 [3168] DEBUG NHibernate.Impl.SessionImpl [(null)] - opened session





but look the red text, these is another session opened..does the OpenSessionInViewModule not support Transactoin?:confused:

thanks for all reply.

Mark Pollack
11-21-2006, 06:49 AM
Hi,

There was a bug that I just fixed regarding using the OpenSessionInViewModule. You should configure the module by using the declaration you list above and also, if the name of your session factory object is not "sessionFactory", the specify the name in the application configuration settings section of you web.config, like below.


<appSettings>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.SessionFactoryObjectName" value="SessionFactory"/>
</appSettings>


Here I used a capital 'S' for SessionFactory. You can pick up the latest build from the download (http://www.springframework.net/downloads/Spring.Data.NHibernate/) page. FYI, there are even more debug statement in Spring now to help follow what is happening.

The new download will also required you to add a new 'common' logging section like shown below and reference the Common.Logging.dll and Common.Logging.Log4Net129.dll.


<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>


and


<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter , Common.Logging.Log4Net129">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="EXTERNAL" />
</factoryAdapter>
</logging>
</common>


You still need to place the transaction attribute on your methods or configure transactional proxies in your configuration file.

Mark

Tommy_Shen
12-01-2006, 12:58 PM
sorry, I still get this exception, I have looked the log file:

2006-12-01 12:57:19,640 [1] DEBUG NHibernate.Impl.SessionImpl [(null)] - initializing non-lazy collections
2006-12-01 12:57:19,640 [1] DEBUG NHibernate.Loader.Loader [(null)] - done entity load
2006-12-01 12:57:19,640 [1] DEBUG Spring.Data.NHibernate.HibernateAccessor [(null)] - Not closing pre-bound Hibernate Session after HibernateTemplate
2006-12-01 12:57:19,640 [1] DEBUG NHibernate.Transaction.AdoTransaction [(null)] - rollback
2006-12-01 12:57:19,640 [1] DEBUG NHibernate.Transaction.AdoTransaction [(null)] - running AdoTransaction.Dispose()
2006-12-01 12:57:19,640 [1] DEBUG NHibernate.Impl.SessionImpl [(null)] - transaction completion
2006-12-01 12:57:19,656 [1] ERROR NHibernate.LazyInitializationException [(null)] - Failed to lazily initialize a collection - no session
NHibernate.LazyInitializationException: Failed to lazily initialize a collection - no session
2006-12-01 12:57:19,656 [1] DEBUG Spring.Data.NHibernate.Support.OpenSessionInViewMo dule [(null)] - Closing single Hibernate Session in OpenSessionInViewFilter
2006-12-01 12:57:19,656 [1] DEBUG Spring.Data.NHibernate.SessionFactoryUtils [(null)] - Closing Hibernate Session
2006-12-01 12:57:19,656 [1] DEBUG NHibernate.Impl.SessionImpl [(null)] - closing session
2006-12-01 12:57:19,656 [1] DEBUG NHibernate.Impl.SessionImpl [(null)] - disconnecting session
2006-12-01 12:57:19,656 [1] DEBUG NHibernate.Connection.ConnectionProvider [(null)] - Closing connection
2006-12-01 12:57:19,656 [1] DEBUG NHibernate.Impl.SessionImpl [(null)] - transaction completion