3 minute read.

NHibernate. (Another Guide). For Visual Studio 2005.

Paul Anthony / March 13, 2008

Posted in: Archive

NHibernate..Oh how I have struggled with you for the past day and a half or so..But eventually got there. Here’s what to do with Visual Studio 2005 that they dont tell you anywhere else.

In your bin folder…I have a hibernate.cfg.xml file.. Which looks like this badboy.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<hibernate-configuration xmlns=”urn:nhibernate-configuration-2.2″>
<property name=”connection.connection_string”>Data Source=localhost\SQLEXPRESS;Initial Catalog=ncatalog;Trusted_Connection=Yes;</property>
<property name=”connection.provider”>NHibernate.Connection.DriverConnectionProvider</property>
<property name=”dialect”>NHibernate.Dialect.MsSql2000Dialect</property>
<property name=”connection.driver_class”>NHibernate.Driver.SqlClientDriver</property>
<property name=”cache.use_query_cache”>false</property>
<property name=”connection.isolation”>ReadCommitted</property>
<property name=”default_schema”>dbo</property>
<property name=”show_sql”>true</property>

I also have my hbm.xml file in there…which looks like this, notice the URN:hibernate-mapping-2.2. If you get invalid schema errors, its prob because the example in the quickstart uses 2.0. Also notice the properties of “namespace” and “assembly”. These aren’t in the freakin example either. Why the example doesn’t use an identity column I have no idea, it must be the most common of table structures.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<hibernate-mapping xmlns=”urn:nhibernate-mapping-2.2″ namespace=”NewsmanagerDLL” assembly=”NewsmanagerDLL”>
<class name=”NewsmanagerDLL.Authors” table=”tbl_authors”>
<id name=”id” column=”fld_author_id” type=”Int32″>
<generator class=”identity” />
<property name=”authorname” column=”fld_author_name” type=”String” length=”40″/>
<property name=”isauthoradmin” column=”fld_author_admin” type=”Boolean” />
<property name=”authorusername” column=”fld_author_user” type=”String” length=”40″/>
<property name=”authoremail” column=”fld_author_email” type=”String” length=”40″/>
<property name=”authorpassword” column=”fld_author_pass” type=”String” length=”40″/>
<property name=”authornotify” column=”fld_author_notify” type=”Boolean”/>

Put your business logic layers in a separate dll, i.e. a new project. Compile the dll, add it as a reference in your NHibernate project. Oh did I mention the error…

Could not find a getter for property ‘Id’ in class

means that the xml file is being read…but the class properties might be uppercase. change them all to lower case. You can figure out my properties from my xml file.

nhibernate.gifThen use AddFile instead of AddAssembly..I couldn’t find the “embed resources property” in visual studio 2005. See screenshot to the right..clarification on this welcome.

Dim cfg As Configuration = New Configuration
Dim factory As ISessionFactory = cfg.BuildSessionFactory
Dim session As ISession
session = factory.OpenSession
Dim transaction As ITransaction
transaction = session.BeginTransaction
Dim objAuthor As New Authors
objAuthor.AuthorEmail = “paul@webdistortion.com”
objAuthor.AuthorName = “NHiver”
objAuthor.AuthorNotify = True
objAuthor.AuthorPassword = “Nhibernate”
objAuthor.IsAuthorAdmin = True

Leave me a comment if this cleared anything up for you. Oh – and take a gander at some other programming related posts.

  • guide
  • nhibernate
  • Programming
  • vb.net
  • visual studio 2005 major issues

5 responses to “NHibernate. (Another Guide). For Visual Studio 2005.

  1. The embed ressource is not available in the web project solutions as it is filesystem based. Instead use a class library or if you still want it in a web project use a web application project

  2. Hi,

    How did you solve that NHibernate doesn’t show up in the .NET references in “Add reference” (VS2005, web/C# project).

  3. The description given for nhibernate is nice and

    simple.In the above example you had given the explanation

    only for insert option.But how the nhibernate works for

    Update,Delete and Select options explanations can also be


Leave a Reply

Your email address will not be published. Required fields are marked *