Ok... I know this question has been posted many times, but I am still having issues. Here's the context of my situation. I am working with the Asp.Net MVC 1.0 framework with NHibernate (duh) and Spring.NET. Currently I am unable to work with a single hibernate session per request. When calling: SessionFactory.GetCurrentSession() I receive the error "No CurrentSessionContext configured ( ... )".
I have added the "OpenSessionInViewModule" within the <httpModules> section of my web.config. If I understand things correctly, this will aid in the one-session-per-request idea.
My spring context file that defines the session factory looks something like this...
...
<object id="sessionFactory" ...> <property name="DbProvider" ref="DbProvider"/> <property name="HibernateProperties"> <dictionary> <entry key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <entry key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/> <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> <entry key="show_sql" value="true"/> <entry key="hbm2ddl.auto" value="create"/> <entry key="current_session_context_class" value="Web" /> </dictionary> </property> </object>
...
The entry of concern is "current_session_context_class". What should the value be? "thread", "thread_static" or "web"? Everyone seems to have a different answer to this question.
From what I gather by reading docs and blogs, I should be good to go at this point, but like I mentioned earlier the call to SessionFactory.GetCurrentSession() throws an exception. If I just use SessionFactory.OpenSession(), life is great and I can save/update objects to the database, but obviously this is opens a different session every time.
Suggestions? I appreciate the help!
Bryan
|