-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: No CurrentSessionContext configured (set the property cur...
PostPosted: Fri Jun 26, 2009 2:55 pm 
Newbie

Joined: Fri Jun 26, 2009 2:22 pm
Posts: 6
Hi Folks,

I'm new to NHibernate. I've created a vs solution with a couple of c# 3.5 class library projects to test the NHibernate waters. One of my c# projects is a collection of NUnit tests to test out my domain, repositories, etc. In NUnit project I have a app.config with the NHibernate configuration info. When I try to get an ISession using GetSessionFactory().GetCurrentSession() I get the following error:

No CurrentSessionContext configured (set the property current_session_context_class)!

The strange thing is that the proeprty is set. I'm using:

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

I've looked everywhere on the net but can't find an answer. The only thing I could think of is that 'Web' may not work if I'm using a class library. Don't know. Here's my session factory class if that would help:

Code:
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;

namespace Infrastructure.Repository
{
    public class SessionFactory
    {

        private static ISessionFactory _SessionFactory;

        private static void Init()
        {
            var config = new Configuration();

            config.AddAssembly("Infrastructure.Repository");

            log4net.Config.XmlConfigurator.Configure();

            config.Configure();

            _SessionFactory = config.BuildSessionFactory();
        }

        public static ISessionFactory GetSessionFactory()
        {
            if (_SessionFactory == null)
            {
                Init();
            }

            return _SessionFactory;
        }

        public static ISession GetNewSession()
        {
            return GetSessionFactory().OpenSession();
        }

        public static ISession GetCurrentSession()
        {
            return GetSessionFactory().GetCurrentSession();
        }
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.