NHibernate 1.2 vs. 2.0.x vs. 2.1.0 Configuration Settings

.NET Musings

NHibernate 1.2 vs. 2.0.x vs. 2.1.0 Configuration Settings

Technorati Tags:

There are a great deal of really cool changes between NHibernate 1.2 and 2.0.1 and 2.1.0, but the one change that I get the most questions about is configuration. Between each of these versions the configuration has changed.

Web.Config/App.Config Settings for Version 1.2:
 
<configuration>
  <configSections>
    <section name="nhibernate"
       type="System.Configuration.NameValueSectionHandler, System,
       Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <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="{blah blah}"/>
    <add key="hibernate.connection.isolation" value="ReadCommitted"/>
  </nhibernate>
</configuration>
Web.Config/App.Config settings for Version 2.0.x
<configuration>
  <configSections>
    <section name="hibernate-configuration"
      type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider, NHibernate</property>
      <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">Server={blah blah}</property>
      <property name="connection.isolation">ReadCommitted</property>
    </session-factory>
  </hibernate-configuration>
</configuration>
Web.Config/App.Config settings for Version 2.1.0
<configuration>
  <configSections>
    <section
      name="hibernate-configuration"
      type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="Sample.DAL.Tests">
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">Data Source=localhost\dev08;Initial Catalog=SteveB;Integrated Security=True;</property>
      <property name="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
      <property name="connection.isolation">ReadCommitted</property>
      <property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
      <mapping assembly='SteveB'/>
    </session-factory>
  </hibernate-configuration>
</configuration>


Hopefully this will help out those transitioning from 1.2 to 2.0 to 2.1.0 (or, looking at a one version’s sample and trying to get it to work in 2.0)

Happy coding!

Comments (2) -

  • krishna

    3/16/2010 7:30:33 AM |

    I get below error

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Unrecognized configuration section hibernate-configuration.

    Source Error:


    Line 18:   </configSections>
    Line 19:     <!-- BEGIN : hibernate -->
    Line 20:   <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    Line 21:     <session-factory name="WatchDog.test">
    Line 22:       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>


    Source File: D:\BFS\projects\WatchDog\WatchDog\WatchDog\web.config    Line: 20


    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

  • PhilJapikse

    3/16/2010 7:35:10 AM |

    Make sure your config sections entry specify "hibernate-configuration" and not "nhibernate-configuration"

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

Comments are closed
Managed Windows Shared Hosting by OrcsWeb