IT Staff

Blog về chuyên ngành IT

Configuration changes in NHibernate 2.0

leave a comment »

nhibernate 2.0

nhibernate 2.0

I downloaded NHibernate 2.0 today and started to play around with it, only to be greeted by a host of configuration errors like System.InvalidOperationException : Could not find the dialect in the configuration. It was then I remembered reading somewhere about some changes to the configuration syntax, so I downloaded the source and looked at the examples (after a brief, ill-fated search for NHibernate 2.0-specific documentation*). Here is an example of how an App.config looked for NHibernate 1.2:

<?xml version="1.0" encoding="utf-8" ?>
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler,
             System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
    <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="hibernate.connection.connection_string" value="Server=INNORIA-4; Initial Catalog=iTMDBTemp;
           User Id=sa;Password=1234;" />
    <add key="hibernate.show_sql" value="true" />

And here is the equivalent for version 2.0:

<?xml version="1.0" encoding="utf-8" ?>
   <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,
              NHibernate" />
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
     <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
     <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
     <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
     <property name="connection.connection_string">Server=INNORIA-4;Initial Catalog=iTMDBTemp;
            User Id=sa;Password=1234;</property>
     <property name="show_sql">true</property>

The main changes are:
  • We aren’t using an nhibernate configuration section, it’s hibernate-configuration now (yay for more typing! :P).
  • We now have a session-factory child node for adding the configuration properties.
  • We aren’t adding properties using the <add key="..." value="..." /> syntax. Instead we are using <property name="...">(property value)</property>.
  • The property names aren’t prefixed by “hibernate” anymore, so “hibernate.connection.provider” becomes “connection.provider“.

Moral of the story is to check the source first — the NHibernate.Examples folder is filled with helpful goodies. 🙂 Svend Tofte also has a helpful post on setting up NHibernate 2.0.


Written by Xavier

Tháng Mười 20, 2008 lúc 7:41 sáng

Posted in My Ideas

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập: Logo

Bạn đang bình luận bằng tài khoản Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s

%d bloggers like this: