Welcome to SofiaDev.Org's Blogs Sign in | Join | Help

Configuration changes in NHibernate 2.0

I was upgrading an NH 1.x project to 2.0 recently, when I've found out there are actual config changes in NH 2.0, compared to the well known 1.x set of builds.

Long story in short, here it is:

In NH 1.x, we used to integrate NH into our projects by defining a new configuration section, like this:

<configSections>
   <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.1.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>

This statement is being used for declaring our NH addiction. Then we add the actual section underneath:

<nhibernate>
    <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
    <add key="hibernate.dialect" value="NHibernate.Dialect.Oracle9Dialect"/>
    <add key="hibernate.connection.driver_class" value="NHibernate.Driver.OracleDataClientDriver"/>
    <add key="hibernate.connection.connection_string" value="Data Source=//win2003:1521/dbname;Persist Security Info=False;User ID=username;Password=password"/>
    <add key="hibernate.connection.isolation" value="ReadCommitted"/>
    <add key="hibernate.default_schema" value="defaultschema"/>
  </nhibernate>
  <connectionStrings>


So, it turned out that in NH 2.0, we have a new type for the NH config section. Instead of using System.Configuration.NameValueSectionHandler, the NH dev team has switched that with a new type: NHibernate.Cfg.ConfigurationSectionHandler. Here's an example:

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

And the actual section:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
      <property name="connection.connection_string">Data Source=//win2003:1521/dbname;Persist Security Info=False;User ID=username;Password=password</property>
      <property name="default_schema">defaultschemanamegoeshere</property>
      <property name="show_sql">true</property>
    </session-factory>
  </hibernate-configuration>


Cheers,
Br.
Published 26 Септември 2008 05:51 by branimir

Comments

# re: Configuration changes in NHibernate 2.0

19 Септември 2011 03:43 by Ingrid23Powell
Would like to utilize your time for your own activities? You will be able to do it utilizing the <a href="http://www.qualityessay.com/buy-an-essay.html">buy an essay</a> service.

# re: Configuration changes in NHibernate 2.0

11 Октомври 2011 15:48 by OPAL25Mullins
Now men have a chance to use an assistance of the thesis writing services , which can finish supreme thesis titles more or less about this topic. But I advice to determine the famous dissertation writing services to buy a thesis paper from.                              
Anonymous comments are disabled