-->
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: Error: Object reference not set to an instance of an object.
PostPosted: Thu Apr 02, 2009 9:44 am 
Newbie

Joined: Thu Apr 02, 2009 9:30 am
Posts: 2
Hello,

I'm new to nHibernate and am trying to get a quickstart working and have run into the following error:

Object reference not set to an instance of an object.

I've searched all over the place for an answer and tried reading through the documentation and i can't find an answer.

Thanks in advance!


Hibernate version: Build 2.0.1.GA

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
    namespace="QuickStart" assembly="QuickStart">

  <class name="Cat" table="Cat">

    <!-- A 32 hex character is our surrogate key. It's automatically
            generated by NHibernate with the UUID pattern. -->
    <id name="Id">
      <column name="CatId" sql-type="int32" not-null="true"/>
    </id>

    <!-- A cat has to have a name, but it shouldn' be too long. -->
    <property name="Name">
      <column name="Name" length="16" not-null="true" />
    </property>
    <property name="Sex" />
    <property name="Weight" />
  </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Dim helper As New QuickStart.NHibernateHelper
        Dim session As ISession = QuickStart.NHibernateHelper.GetCurrentSession()
        Dim tx As ITransaction = session.BeginTransaction
        Dim princess As QuickStart.cat = New QuickStart.cat
        princess.name = "Princess"
        princess.sex = "F"
        princess.weight = 34.34
        session.Save(princess)
        tx.Commit()

        QuickStart.NHibernateHelper.CloseSession()



    End Sub


Full stack trace of any exception that occurs:
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
NHibernate.Cfg.Environment.LoadGlobalPropertiesFromAppConfig() +412
NHibernate.Cfg.Environment..cctor() +221

[TypeInitializationException: The type initializer for 'NHibernate.Cfg.Environment' threw an exception.]
NHibernate.Cfg.Environment.get_Properties() +0
NHibernate.Cfg.Configuration.Reset() +401
NHibernate.Cfg.Configuration..ctor(SettingsFactory settingsFactory) +84
NHibernate.Cfg.Configuration..ctor() +56
NhibernateQuickStart.QuickStart.NHibernateHelper..cctor() in C:\Projects\Research\NhibernateQuickStart\NhibernateQuickStart\domain\NHibernateHelper.vb:11

[TypeInitializationException: The type initializer for 'NhibernateQuickStart.QuickStart.NHibernateHelper' threw an exception.]
NhibernateQuickStart.QuickStart.NHibernateHelper.GetCurrentSession() in C:\Projects\Research\NhibernateQuickStart\NhibernateQuickStart\domain\NHibernateHelper.vb:24
NhibernateQuickStart.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Projects\Research\NhibernateQuickStart\NhibernateQuickStart\catpage.aspx.vb:9
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Name and version of the database you are using:
sql server 200

The generated SQL (show_sql=true):
none

Debug level Hibernate log excerpt:
i don't know.

my related web.config:
Code:
<configSections>
      <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
      <session-factory>
         <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
         <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
         <property name="connection.connection_string">Server=DEV2;initial catalog=nhibernate;Integrated Security=TRUE</property>
         <mapping assembly="NhibernateQuickStart"/>
      </session-factory>
   </hibernate-configuration>



EDIT:

I moved the config stuff to a nhibernate.cfg.xml file and put it in the root of my project and now this error is solved. I have new errors now, but i think i can figure them out.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 3:16 pm 
Hello

Please check if you have initialized your objects, QuickStart and NHibernateHelper

Maybe its your problem.

[]s


Top
  
 
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.