Kello’s Code Corner

May 5, 2009

Why I don’t choose to use NHibernate

Filed under: .NET,NHibernate — jonaskello @ 21:30

If my job was to retrieve data from the database I would never choose NHibernate!

DataSets and DataReader are much more useful for this.

But my job is not to retrieve data from the database. It is to build a system that solves a complex problem.

If my job was to build a system that solves a complex problem I would never choose NHibernate!

I would choose an approach that can handle complex problems. I would choose to build a Domain Model!

If I choose to build a Domain Model I would make sure that it was built to have a long lifespan.

If I wanted a long lifespan for my Domain Model I would make sure we only need to change it when the business domain changes, not when software technologies for data access and other such concerns change.

To give my Domain Model a long lifespan I would base it on the technology that is the least likely to change. This would be something that have not changed in a long time and have a lot of other software built on it so it cannot change for a long time.

The way basic classes work in object models have not changed since the ideas were formed in the 1960s. In the Microsoft world, classes/objects have not changed since Microsoft.NET framework 1.0 was introduced.  The whole Microsoft.NET framework is built on Common Language Runtime (CLR) classes/objects.

I would base my Domain Model on just basic classes, also known as Plain Old CLR Objects (POCO). PCOO objects are classes that does not inherit from or are in any way are associated with anything “special” such as a Microsoft DataSet base class. This way POCO classes can stay 100% focused on business problems and don’t have to change when data access technologies change.

Some of the POCO objects in the Domain Model would have to be saved to a database. In order to do this and not involve any of the technology to do it in the Domain Model I would have to use Persistence Ignorance (PI). PI means that the object in the Domain Model have no idea how they are being saved and loaded from the persistent medium (the database).

To use PI I would have to use an existing persistence framework that supports PI or build my own data access framework that supports PI.

I would choose to use an existing persistence framework to save time. I would want to use the framework that does not depend on a small vendor and does not infer extra cost on the project. I would want to use a framework that are used in a lot of other systems and have a lot of documented credibility.

The only framework that currently matches these criteria is NHibernate.

I do not choose to use NHibernate but I use it as a consequence of my other more important choices!

DotNetKicks Image
About these ads

6 Comments »

  1. ;-)

    Wait, wha? How’d I get here? So what you’re saying is that you are using NHibernate against your will? That’s horrible. What terrible crimes have you committed against humanity to warrant such a cruel sentence? Hibernate mappings make baby Jeebus cry.
    ;-)

    If you think I’m being serious, please refer to the emoticons. If you still think I’m being serious then please direct all your anger towards this period->..<- this one’s cool. the first one is a jerk.

    Comment by Michael D. Hall — May 6, 2009 @ 17:17 | Reply

  2. Pretty tricky the way you turned it around at the end. ;-)

    Comment by Lee Dumond — May 6, 2009 @ 19:38 | Reply

  3. “In the Microsoft world, classes/objects have not changed since Microsoft.NET framework 1.0 was introduced.” – lol, that is not true :) if your knowledge is same with nHibernate then we are back on your “I would never choose NHibernate!”. And with “I would never choose NHibernate!” I do agree :)

    Comment by Rori — May 28, 2009 @ 14:36 | Reply

    • The objects I was refering to were of course Plain Old (POCO) objects and I think the “old” part of that that name says it all..

      Comment by jonaskello — August 17, 2009 @ 18:59 | Reply

  4. Indeed if you want to just store/retrieve database without object mappings then just accessing the database straight away is the fastest possible way. Then I would use the datareader but not datasets as datasets too high level.

    I don’t understand what complex application logic has anything to do with NHibernate. NHibernate is just a method to persist object data to a relational database.

    The same about changing technologies. You don’t need to “upgrade” to other ORM libraries or newer versions. Especially if that requires lots of modifications. NHibernate just sits on top of technologies that are very mature. So yet again a very strange opinion you are having.

    Seems like you just read the bullshit bingo list and wrote a post around it as it lacks proper statements and makes it very clear that you do not know that NHibernate or ORM in general is about.

    Comment by Ramon Smits — December 17, 2009 @ 21:04 | Reply

    • My goal is to build good Domain Models, not to build infrastructure such as persistance. The point of the post (which I think you missed or maybe you did not read the whole post) is that NHibernate is the only free ORM that you can use to build a POCO Domain Model, therefore it is my ORM of choice. If you want to know what Domain Model has to do with complex application logic I suggest you read Patterns of Enterprise Application Architecture by Fowler where he explains why using Domain Model may be a good choice for complex application logic.

      Comment by jonaskello — December 29, 2009 @ 18:57 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: