-->
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.  [ 8 posts ] 
Author Message
 Post subject: <hibernate-configuration> section not read from app.co
PostPosted: Fri Jul 06, 2007 10:19 pm 
Beginner
Beginner

Joined: Fri Jul 06, 2007 9:27 pm
Posts: 22
I'm creating a simple console demo app as an NHibernate learning exercise. I have put configuration information in an app.config file, in a <hibernate-configuration> section (rather than a <hibernate> section), as shown in Listing 3.3 of the ebook version of 'NHibernate in Action'.

Here is my app.config section:

<!-- NHibernate Configuration -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.MsSqlCeDialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Data Source="D:\DCV Documents\Visual Studio 2005\Demos\NHibernateDemo1\NHibernateDemo1\NHibernateDemo1.sdf"
</property>
</session-factory>
</hibernate-configuration>

And here is the code I am using to configure NHibernate:

// Create configuration object
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernateDemo1");

// Create an NHibernate session factory
m_SessionFactory = cfg.BuildSessionFactory();

When the AddAssembly() call executes, I get the error: "The dialect was not set. Set the property hibernate.dialect." As you can see, the dialect is in fact set.

The log file includes the following entry:

2007-07-06 20:57:58,625 [9] INFO NHibernate.Cfg.Environment [(null)] <(null)> - nhibernate section not found in application configuration file

So, to me, it looks like NHibernate is not looking for a <hibernate-configuration> section, only an <nhibernate> section. As a result, it isn't finding any of the configuration information in my app.config file.

Can I use a <hibernate-configuration> in my app.config file, or am I limited to using only an <nhibernate> section? Or does my problem lie somewhere else?

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 2:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, you can use <hibernate-configuration>, but you have to specify a different configuration section handler (NHibernate.Cfg.ConfigurationSectionHandler in assembly NHibernate).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 7:19 am 
Beginner
Beginner

Joined: Fri Jul 06, 2007 9:27 pm
Posts: 22
Thanks, Sergey. I think that's what I what I have specified as the configuration section handler. Here is the spec from <configSections>:

<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>

Any other suggestions? Thanks again for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 12:11 pm 
Beginner
Beginner

Joined: Fri Jul 06, 2007 9:27 pm
Posts: 22
I may have found an answer. I looked up the log message in the NHibernate source code, and there is what I found:

private static void LoadGlobalPropertiesFromAppConfig()
{
object config = ConfigurationSettings.GetConfig( "nhibernate" );
if( config == null )
{
log.Info( "nhibernate section not found in application configuration file" );
return;
}
...
}

From this, it would appear that NHibernate looks only for an <nhibernate> section.

Am I missing something, or is that in fact the case?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 1:49 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, it just looks for hibernate-configuration settings elsewhere. Are you sure they are not getting picked up? The log message may be confusing, it only means that the nhibernate section wasn't found, it doesn't imply anything more than that.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 4:26 pm 
Beginner
Beginner

Joined: Fri Jul 06, 2007 9:27 pm
Posts: 22
Here's the log (level=INFO). When I use a a <hibernate> section with the same info, NHibernate configures without problem. Any thoughts? Thanks again!

2007-07-07 15:23:22,359 [9] INFO NHibernate.Cfg.Environment [(null)] <(null)> - NHibernate 1.2.0.4000 (1.2.0.4000)
2007-07-07 15:23:22,546 [9] INFO NHibernate.Cfg.Environment [(null)] <(null)> - nhibernate section not found in application configuration file
2007-07-07 15:23:22,593 [9] INFO NHibernate.Cfg.Environment [(null)] <(null)> - Bytecode provider name : lcg
2007-07-07 15:23:22,609 [9] INFO NHibernate.Cfg.Environment [(null)] <(null)> - Using reflection optimizer
2007-07-07 15:23:24,046 [9] INFO NHibernate.Cfg.Configuration [(null)] <(null)> - Searching for mapped documents in assembly: NHibernateDemo1
2007-07-07 15:23:24,171 [9] INFO NHibernate.Cfg.Configuration [(null)] <(null)> - Adding embedded mapping document: NHibernateDemo1.Model.Customer.hbm.xml
2007-07-07 15:23:24,171 [9] INFO NHibernate.Cfg.Configuration [(null)] <(null)> - Mapping resource: NHibernateDemo1.Model.Customer.hbm.xml
2007-07-07 15:23:24,328 [9] ERROR NHibernate.Cfg.Configuration [(null)] <(null)> - Could not compile the mapping document: NHibernateDemo1.Model.Customer.hbm.xml
NHibernate.MappingException: Could not compile the mapping document: NHibernateDemo1.Model.Customer.hbm.xml ---> NHibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at NHibernate.Dialect.Dialect.GetDialect()
at NHibernate.Dialect.Dialect.GetDialect(IDictionary props)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String name)
--- End of inner exception stack trace ---


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 08, 2007 2:23 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Right, I think a call to Configuration.Configure() should cure it:
Code:
Configuration cfg = new Configuration();
cfg.Configure(); // read settings from hibernate-configuration
cfg.AddAssembly("NHibernateDemo1");


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 08, 2007 8:37 am 
Beginner
Beginner

Joined: Fri Jul 06, 2007 9:27 pm
Posts: 22
Right--that's got it! Thanks again for your help!


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