Trying NHibernate

I was recently doing and small research project and got kinda tired of mechanically spitting out all those boring chants like

using (var cmd = new SqlCommand("SELECT foo, bar FROM abc", conn)
{
...
}

I felt like my ride on the ORM train is long overdue. I’ve been planning to try NHibernate too long, and now I have finally found free time to do that.

The beginning was pretty decent. http://www.hibernate.org, downloads, binaries, and source, documentation. So far so good.

Never mind that the documentation is for version 1.2, and current version is 2.0. It is open source, after all, what did you expect? Moving on to quick start.

ASP.NET? No, thanks, I prefer console applications for tests. Maybe I am old fashioned. Anyhow, seems to work alright. Only my assembly (and namespace) is not called QuickStart, it is called HibernateFirst. Had to fix it in about 8 places. Not cool. The error messages were pretty decent though, and quickly pointed me to the problem.

They neglected to say I need to include the mapping file as a resource. It’s so obvious, huh? The error message was not very helpful this time.

You should now create the database and this table manually, and later read the Toolset Guide if you want to automate this step. No no, I want to automate this step now. Skip ahead to the toolset guide.

Paragraph 16.1.2, “running the tool”.

java -cp hibernate_classpaths net.sf.hibernate.tool.hbm2ddl.SchemaExport options mapping_files

What?! What Java? What classpath? I don’t have a single jar in the binaries, what are they talking about? Searching the Internet for the f-fine tool. No trace of it. Going to the source. Well, there is a NHibernate.Tool.hbm2ddl.SchemaExport class, but it has no Main method. What gives?

Leave a Reply

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