-->
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.  [ 9 posts ] 
Author Message
 Post subject: Configuration.Configure() confusion
PostPosted: Wed Nov 09, 2005 4:19 am 
Newbie

Joined: Wed Nov 02, 2005 6:18 am
Posts: 7
The place where <=== ERROR is shown causes an *Object reference not set to an instance of an object* error.

The file hibernate.cfg.xml has been placed in the output directory, so it can see it.

I have included a copy below, just in case it's layout is the cause.

Can anyone please tell me why

Thanks

BOb

Code:
public sealed class Global
    {
        private static Configuration nhConfig;
        private static ISessionFactory nhFactory;

        public static ISession NHSession
        {
            get
            {
                if (nhFactory == null)
                {
                    nhConfig = new Configuration();
                   
                    nhConfig.Configure();                       <===== ERROR

                    nhConfig.AddAssembly("DAL");

                    nhFactory = nhConfig.BuildSessionFactory();                   
                }

                return nhFactory.OpenSession();
            }
        }

        private Global ()
        {
        }
    }


hibernate.cfg.xml

Code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <configSections>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
      <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"   />
   </configSections>
   
   <log4net>
      <appender name="rollingFile" type="log4net.Appender.RollingFileAppender, log4net" >         
         <param name="File" value="log.txt" />
         <param name="AppendToFile" value="true" />
         <param name="RollingStyle" value="Date" />
         <param name="DatePattern" value="yyyy.MM.dd" />
         <param name="StaticLogFileName" value="true" />
         <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>
      <root>
         <priority value="DEBUG" />
         <appender-ref ref="rollingFile" />
      </root>   
   </log4net>

   <nhibernate>
      <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
      <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
      <add key="hibernate.connection.connection_string" value="Server=localhost;Database=LLBProTest;User=sa;Pwd=sqladmin;" />
      <add key="hibernate.show_sql" value="true" />
   </nhibernate>
</configuration>

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:03 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you post the full exception? (with the trace)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:42 am 
Newbie

Joined: Wed Nov 02, 2005 6:18 am
Posts: 7
I am not sure how this will help, but what do I know, if I knew the answer, this posting would not be here

BOb

Code:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="NHibernate"
  StackTrace:
       at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
       at NHibernate.Cfg.Configuration.Configure(String resource)
       at NHibernate.Cfg.Configuration.Configure()
       at DAL.Global.get_NHSession() in C:\Documents and Settings\BNPardoe\My Documents\Visual Studio 2005\Projects\JavaConversion\DAL\Global.cs:line 22
       at DAL.AddressDAL..ctor() in C:\Documents and Settings\BNPardoe\My Documents\Visual Studio 2005\Projects\JavaConversion\DAL\AddressDAL.cs:line 24
       at ACRLogistics.Address..ctor() in C:\Documents and Settings\BNPardoe\My Documents\Visual Studio 2005\Projects\JavaConversion\Address\Address.cs:line 203
       at ACRLogistics.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\BNPardoe\My Documents\Visual Studio 2005\Projects\JavaConversion\WinTester\WindowsApplication1\Form1.cs:line 22
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ACRLogistics.Program.Main() in C:\Documents and Settings\BNPardoe\My Documents\Visual Studio 2005\Projects\JavaConversion\WinTester\WindowsApplication1\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()



Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 7:15 pm 
Newbie

Joined: Thu Jun 09, 2005 12:48 pm
Posts: 5
Location: Portland, Oregon
I am having the same problem. If I progmatically load the config it works but I can't get it to work with my config file "my.cfg.xml". I put the config file in the bin directory, but it was looking for it in system32. I put it there and got a different error.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 11:55 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Code:
nhConfig.Configure();

Is used to read the configuration from the file hibernate.cfg.xml.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Last edited by KPixel on Thu Nov 17, 2005 12:33 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 12:02 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Actually, it will try the {app|web}.config, then hibernate.cfg.xml.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 12:32 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Hum, yes; it is Configure(...) which ignores the config file.

To bobpardoe, I didn't read your post carefully the first time.
Your hibernate.cfg.xml file has the layout of a app/web.config file.

Here is how hibernate.cfg.xml should be:
Code:
<?xml version="1.0" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.0" >
   <session-factory name="NHibernateEg">
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      ...
   </session-factory>
</hibernate-configuration>

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 1:58 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The NullReferenceException is thrown in 1.0 if no <hibernate-configuration> node with the right XML namespace was found - check that you have the xmlns declaration on it. 1.0.1 that was just released should give a better error message.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 12:02 pm 
Newbie

Joined: Thu Sep 29, 2005 3:30 pm
Posts: 3
Add a key in web/app.config
like
<add key="nhibernate.config" value="~/nhibernate.config" />


For web apps we use
configuration.Configure( HttpContext.Current.Request.MapPath(ConfigurationSettings.AppSettings["nhibernate.config"]) ).BuildSessionFactory()

For non-web apps we use
configuration.Configure(ConfigurationSettings.AppSettings["nhibernate.config"]).BuildSessionFactory());


Question:
Is it possible to configure
<session-factory> and <mapping assembly> in web.config?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.