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.  [ 6 posts ] 
Author Message
 Post subject: Changing NH configuration-settings in app.config at runtime
PostPosted: Tue Aug 05, 2008 4:20 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Hibernate version: 2.0 RC1

I want to programmatically change my NHibernate configuration which I've put in the app.config file.
My app-config looks like this:
Code:
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate, Version=2.0.0.3001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"/>   
  </configSections>
 
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>

      <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">...</property>
      <property name="connection.isolation">ReadCommitted</property>
      <property name="default_schema">...</property>
      <mapping assembly="...."/>

    </session-factory>
  </hibernate-configuration>
Simple. When I configure NHibernate, this all works. My application runs etc...

Now, I want to build some functionality in where I can change these configuration values at runtime.
Therefore, I do this:
Code:
Configuration config = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
object section = config.GetSection(CfgXmlHelper.CfgSectionName);

Then , I want to cast the section object to an object that implements IHibernateConfiguration, but this does not work.
In fact, the GetSection method that I call, returns a DefaultSection object instead of the appropriate NHibernate config object.
When I change my code, so that I call the static GetSection method of the ConfigurationManager, I do get the correct result.
So, the code below works:
Code:
section = ConfigurationManager.GetSection (CfgXmlHelper.CfgSectionName);

IHibernateConfiguration hc = section as IHibernateConfiguration;


But, by working in this way, i cannot save my settings offcourse.
Any suggestions ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 2:13 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
i cannot save my settings offcourse


You what the changes written into the file ?

If you only want to change/set some of the hibernate properties during runtime, you can do this:

Code:
Configuration myConfig = new Configuration();
myConfig.SetProperty("hibernate.dialect", NHibernate.Dialect.MsSql2005Dialect")
...
ISessionFactory factory = config.BuildSessionFactory();

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 2:48 am 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
wolli wrote:

You what the changes written into the file ?


That's what I'm saying ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 3:24 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
hmm, just had a look at how we use the configuration and played a bit. Seems that hibernate uses the deprecated IConfigurationSectionHandler interface instead of deriving from ConfigurationSection. Afaik NHibernate 2.0 doesn't support .Net 1.1 anymore, so there is no need for doing this. You can open a JIRA issue and request this being changed to ConfigurationSection. Shouldn't be hard.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 5:53 am 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
wolli wrote:
hmm, just had a look at how we use the configuration and played a bit. Seems that hibernate uses the deprecated IConfigurationSectionHandler interface instead of deriving from ConfigurationSection. Afaik NHibernate 2.0 doesn't support .Net 1.1 anymore, so there is no need for doing this. You can open a JIRA issue and request this being changed to ConfigurationSection. Shouldn't be hard.

Indeed; I'll do that this evening.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 3:33 am 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Unfortunately, it seems that the NHibernate developers do not want to fix / change this ...

http://jira.nhibernate.org/browse/NH-1430


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