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