Thursday, July 9, 2009

CurrentSessionContext call results in "No current session context configured."

Well, I was playing with NHibernate today and trying to create a single session in a windows application that would stay open till I was ready to close it. I was using CurrentSessionContext.Bind(someSession) when I generated this error: "No current session context configured." After some searching around, I discovered that I was missing a line in my Hibernate.cfg.xml file.

< name="current_session_context_class" > thread_static < /property >

Apparently, it can have several settings:
  • managed_web
  • call
  • thread_static
  • web

References:

6 comments:

Thorsten Lorenz said...

Thanks, a short but very helpful post.
Right to the point - solved my problem immediately and thus possibly saved me lots of time otherwise spent searching for a solution.

Anonymous said...

There's a new one called wcf_operation too in NH3 :)

Teamsar said...

Thank you.. :) really nice article..!!

Teamsar said...

Nice.. very nice.. this article is very helpful. thx.. :)

Viktor said...

Thanks a lot!
Your advice has been very helpful!

Unknown said...

has same issue i had consumed todays to fix it thanks it was helpful