-->
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.  [ 5 posts ] 
Author Message
 Post subject: problem with nhibernate file configuration.
PostPosted: Fri Jan 06, 2006 1:38 pm 
Newbie

Joined: Thu Jan 05, 2006 3:59 pm
Posts: 10
I've been using NHibernate for a while. When I configure programmatically, everything's fine. Here's my code:

Code:
                cfg.Properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
                cfg.Properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
                cfg.Properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
                cfg.Properties.Add("hibernate.connection.connection_string", getConnectionString(key));
                cfg.AddAssembly("MyAssembly");
                factoryList[key] = cfg.BuildSessionFactory();


Now, I've moved that configuration into a file, as seen below:

Code:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">

  <session-factory>
    <property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="hibernate.dialect">NHibernate.Dialect.MsSql2000Dialect</property>
    <property name="hibernate.connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="hibernate.connection.connection_string">**HA!  Like I'm gonna post my connection string to a public forum! :-p**</property>

    <mapping assembly="MyAssembly"/>
  </session-factory>

</hibernate-configuration>


When I run this, I get a . . . I forget the .NET equivalent of java's NullPointerException. When I take the mapping line out it works fine . . . except, of course, I don't have any mappings loaded. Any ideas, 'cause I'm stumped.

For reference, here's the stack trace I get when I call cfg.Configure(myXmlTextReader):

Code:
-      [System.NullReferenceException]   "Object reference not set to an instance of an object."
   at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
   at MyAssembly.Hibernate.HibernateSessionFactory.ConfigureSessionFactory(String key) in C:\\Inetpub\\wwwroot\\personal\\Shared_Libraries\\LIB\\MyAssembly\\HibernateCore.cs:line 267
   at MyAssembly.Hibernate.HibernateSessionFactory.PrepareUnitOfWork(HibernateUnitOfWork unit) in C:\\Inetpub\\wwwroot\\personal\\Shared_Libraries\\LIB\\MyAssembly\\HibernateCore.cs:line 189


Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 07, 2006 7:34 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Which version of NHibernate are you using? I remember seeing a stack trace similar to this when the xmlns attribute was left out, but this doesn't look like your problem. Please post the version number and debug-level logs.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 08, 2006 1:32 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Are you still calling:
Code:
cfg.AddAssembly("MyAssembly");
before building the SessionFactory? If it works when progamatically doing the configuration, I assume the mappings are loaded from the assembly properly. If not, the common problem of not setting the mapping files as "EmbeddedResource" in the project would be the likely issue.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 1:49 pm 
Newbie

Joined: Thu Jan 05, 2006 3:59 pm
Posts: 10
Well, I got it working by just manually calling cfg.AddAssembly after loading the config file . . . sans the <mapping> element. Obviously not an elegant solution.

As for your question, sergey, about the version, I'm using NHibernate 1.0.1.

<side-note type="off-topic"><![CDATA[

I am waiting eagerly for 1.1 alpha with that nice happy sub-query functionality I see pending there on JIRA. :-D For that matter, 2.0 would be great, with the full Hibernate 3.1 functionality and support for generics. (you should see the hacks I've gone through to get that working here in the meantime . . . UGLY!) Anything I can do to help (short of time, money or actual design advice . . . so basically limited to moral support) let me know.

]]></side-note> <!-- Dude . . . where'd that XML come from? -->

Unfortunately, at this point, I haven't gotten log4net working quite properly, as this isn't yet ina real-world app, and I'm not sure how to get NUnit to set log4net up. (and I haven't been terribly motivated yet to do so.) So, I don't have the debug logging output at the moment.

I appreciate the attention, and I'll get you the debug output as soon as possible, though it might be a day or two.

Thanks.

-Falken


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 3:48 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Falken224 wrote:
I'm not sure how to get NUnit to set log4net up.


In NHibernate tests we use assembly-level log4net.Config.XmlConfigurator attribute, like this:
Code:
[assembly: log4net.Config.XmlConfigurator()]


This makes log4net read settings from the app.config file.


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