Giving up on NHibernate
I’m currently wrapping up preparations for a “Sogeti Academy” course called “Software Development Best Practices.” It occurred to me that it would be beneficial to our consultants if I (and co-facilitator Bojan Simic) spent some time covering data access strategies, and specifically popular .Net and Java-based ORM solutions. The best .Net programmers that I know use NHibernate as their ORM of choice, so in taking the cue from these folks, I decided to give it a whirl. After spending hours in study and working thoroughly and completely through the tutorials offered on both NHibernate and Fluent NHibernate, I was left confused and flustered angry. *Warning* gratuitous venting follows…
First, I tried following the atrocious “Your first NHibernate based application” tutorial on their official wiki site. Atrocious is a strong word, but certainly applicable here. The writer of this tutorial clearly did not follow his own tutorial to see if it was complete or skipping any steps, because I (along with lots of other people according to the comments) was completely unable to get the application working due to missing steps, and many assumptions being made about knowledge of the tool. Very frustrating. Not to be deterred, I decided to take a look at Fluent NHibernate as some very smart folks recommend delving straight into Fluent NHibernate (Fluent NHibernate is NHibernate minus all the xml-based mapping files). Here again, I was left very unimpressed by the “Your first project” tutorial. After receiving cryptic run-time error messages due to an incomplete tutorial, and posting to stackoverflow.com for solutions, I finally got the application to work after a couple hours of screwing around. This is simply unacceptable for a “your first application” type of tutorial, unless of course your goal is to drive people as far away from your tool as possible. With a working application, I decided to take a look to see how hard it would be to get Linq to NHibernate working. After about 30 minutes of looking around and no clear direction on how to approach Linq to NHibernate, I gave up.
With the release of the .Net Entity Framework 4.0, and an admission that it’s a pretty good tool from Ayende (well-known and well-respected developer), I’m scrapping NHibernate in favor of EF. The Microsoft Quickstart guide provides an easy-to-follow, and most important WORKING basic application in about 15-30 minutes of invested time. It seems that Microsoft has closed the gap between EF and NHibernate substantially since the first version, so I’m going with what works.
I certainly have an open mind with programming in general as well as choosing specific tools, but I refuse to waste any more time on a technology that is so difficult to learn (or at least whose documentation is so deficient) that its most basic tutorials don’t work. It frankly amazes me that NHibernate has any adoption at all given the ridiculously deficient state of their introductory documentation. If someone can point me to documentation that is actually worth spending time on, I’ll be happy to take a look, but for now, I’m going with EF, and it will take a lot for me to look back.

8 Responses to “Giving up on NHibernate”
April 26th, 2010 at: 11:22 pm
I understand your frustration. We created Visual NHibernate to reduce the steep learning curve associated with NHibernate. Maybe it could have helped. http://www.slyce.com
April 27th, 2010 at: 8:19 am
the truth is that EF or L2SQL for that matter lets you start building apps very fast. toy apps, stuff like Northwind are sweet to build with them.
the problem appears when you need to build complex, real world apps.
no offence, but NH is not for retards who can only click and drag and drop…
April 27th, 2010 at: 9:01 am
mem, as I understand, EF allows the construction of far more complex applications than Linq to SQL. Linq to SQL only allows 1-to-1 mapping between tables and classes, and doesn’t allow the DDD approach of generating a DB schema from POCO classes while EF does (and allows 1:many, many:1, etc. mappings). As for EF 4.0 comparison to NH, I’m not qualified to make this comparison, so I won’t venture a try.
How did you learn NH? Can you recommend any good resources? A lot of people know and love NH, but I can’t imagine that they used the official documentation to learn.
April 27th, 2010 at: 9:30 am
First, I read the manual from http://nhforge.org/doc/nh/en/index.html, to have an idea about the concepts involved.
Previously I worked with plain ADO.NET, Sooda, Linq2SQL and llbl.
I knew already that it will not be as easy as with L2S.
Then I googled for sample apps. I use mainly Criteria API and sometimes I still google or read Ayende’s blog for some more complex samples.
Once you master some basic issues, you can build easily more complex queries.
One nice tutorial is http://nhforge.org/blogs/nhibernate/archive/2010/04/25/first-three-nhibernate-quickstart-tutorials-available.aspx
I also setup a Google Alert for “Nhibernate”, to let me know when new stuff about NH appears - this way I discovered your post :))
Haven’t tried Sharp Architecture (because it uses generated code) or Fluent NH (because its not complete)
All in all, I’d never go back to Microsoft persistence stuff.
April 27th, 2010 at: 10:59 am
Andy,
I agree that it would be hard to learn the tools with enough confidence to teach it only from those tutorials. Teaching anything that you’ve never used for a real project is difficult.
I wouldn’t give up on NHibernate. Reading NHibernate in Action, watching the screen-casts from Summer of NHibernate, http://www.summerofnhibernate.com/, and asking questions are how I learned to use it. There are many resources in the community to help you.
The quickstart for EF does not demonstrate SOLID principals. http://msdn.microsoft.com/en-us/library/bb386884(v=VS.100).aspx
shows querying the db directly from the UI layer. This demo shows you a completely scripted example, which for me doesn’t help understanding what EF is about.
Maggie
April 27th, 2010 at: 11:22 am
Hi Maggie,
I definitely agree that the EF quickstart not demonstrating SOLID is really crappy. In my experience, most MS tutorials don’t demonstrate SOLID (or other good programming practices for that matter) which is really annoying and only serves to perpectuate bad code/design. When I went through the tutorial, I split off the EF stuff into a separate project and implemented the repository pattern against it as well (although Ayende says in a blog post that repository is redundant with ORMs like NH which I haven’t yet grokked). I got the quickstart tutorial working in less than 30 minutes whereas I was screwing around for hours with the NH / Fluent NH tutorials. I fully understood going into it that NH / Fluent NH would be harder to learn than EF, but broken tutorials for “hello world”-type applications is just unacceptable IMO, and makes me think that other documentation will be similarly broken/incomplete/misleading. Is NH really that much better than EF 4.0? I don’t know, and I haven’t seen any comprehensive comparisons yet.
Thanks for the links!
April 27th, 2010 at: 4:03 pm
Andy, you can also try Castle Project’s ActiveRecord (http://www.castleproject.org/castle/download.html), which is a thin layer on top of NH and allows you to map entities by using atributes, instead of xml files.
And you can use the full power of NH Criteria API for complex queries.
There are also some screencasts, here: http://castlecasts.com
April 27th, 2010 at: 6:02 pm
It’s a long read, but the Blogger Ayende has a good post with an even greater conversation in the comments section on NHibernate vs. EF 4.0: http://ayende.com/Blog/archive/2010/01/05/nhibernate-vs.-entity-framework-4.0.aspx
In my experience, EF 4.0 finally gives me a viable alternative in many cases to NHibernate that I didn’t have with the previous release and that couldn’t be readily solved with LINQ-to-SQL. I still enjoy LINQ-to-SQL however. I couldn’t sit in front of an audience and provide bullet points on why one is better than another. Ultimately the environment of team experience, existing technology investments, and future technology investment strategy are where I make my decisions on what to use or attempt to use. My first experiences with NHibernate were similarly frustrating and I found books on the subject invaluable. With EF 4.0, I will probably lean heavily toward this over NHibernate because the immediate value of “Commercial Off-the-Shelf” (COTS) has a heavy favoring for ROI. At least developers will have to “make a case” for NHibernate, where-as before they could simply say, “What else does this?”
Leave a Reply