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.  [ 2 posts ] 
Author Message
 Post subject: The type initializer for 'CMSNET.AppCode.NHibernateHelper' t
PostPosted: Wed Aug 27, 2008 6:42 pm 
Newbie

Joined: Wed Aug 27, 2008 6:32 pm
Posts: 1
Hi,
I'm a newbie to NHibernate. I've been trying to figure this out for about a day now..
I have a built the objects and classes as a separate assembly and i'm importing it into my .NET project. When I try to run i get this error

The type initializer for 'CB.AppCode.NHibernateHelper' threw an exception.

I did try to configure in the NHibernateHelper class but i'm not sure if I have to set the configuration object there...plz help..my session is always null...how do I go about it?

Pasting my NHibernateHelper.cs below:

public sealed class NHibernateHelper
{
private const string sessionKey = "nhibernate.current_session";
private static readonly ISessionFactory sessionFactory;

static NHibernateHelper()
{
log4net.Config.XmlConfigurator.Configure();
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration().Configure();

// Get the mapping file path
String mappingPath =
HttpContext.Current.Server.MapPath(
"/cms-checkedout/CodeBase/Mappings/");

// Set up the configuration
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration()
.AddFile(mappingPath + "User.hbm.xml")
.AddFile(mappingPath + "Site.hbm.xml");

// Build the session factory
sessionFactory = config.BuildSessionFactory();
}

public static ISession GetCurrentSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = (ISession)context.Items[sessionKey];

if (currentSession == null)
{
currentSession = sessionFactory.OpenSession();
context.Items[sessionKey] = currentSession;
}

return currentSession;
}

public static void CloseSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = (ISession)context.Items[sessionKey];

if (currentSession == null)
{
// No current session
return;
}

currentSession.Close();
context.Items.Remove(sessionKey);
}

public static void CloseSessionFactory()
{
if (sessionFactory != null)
{
sessionFactory.Close();
}
}
}


And this is my aspx.cs code:


protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
ISession session = NHibernateHelper.GetCurrentSession();
string username = TextBox1.Text;
string password = TextBox2.Text;
User tmpUser = new User();
UserDAO userdao = new UserDAO();
tmpUser = UserDAO.validateUser(username, password);
string validUser = "";
validUser = tmpUser.userName;
if (string.IsNullOrEmpty(validUser))
{
Label1.Visible = true;
Label1.Text = "Invalid username/password";
}
else
{
Response.Redirect("index.aspx");

}


Somebody please help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 2:44 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
Look at the InnerException of your exception. Usually the innermost exception will give you the information needed.


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

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.