Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages and Disadvantages of NHibernate

What are the advantages/disadvantages of using NHibernate ? What kind of applications should be (& should not be) built using NHibernate ?

like image 440
Eros Avatar asked Aug 14 '09 14:08

Eros


2 Answers

Since other ppl have listed advantages I will just list the disadvantages


Disadvantages

  1. Increased startup time due to metadata preparation ( not good for desktop like apps)
  2. Huge learning curve without orm background.
  3. Comparatively Hard to fine tune generated sql.
  4. Hard to get session management right if used in non-typical environments ( read non webapps )
  5. Not suited for apps without a clean domain object model ( no all apps in world dont need clean domain object models) .
  6. Have to jump through hoops if you have badly designed ( legacy ) db schema.
like image 87
Surya Avatar answered Oct 18 '22 12:10

Surya


Advantages:

  1. Flexible and very powerful mapping capabilities.
  2. Caching.
  3. Very polished UnitOfWork implementation.
  4. Future query (article).
  5. Model classes are POCO - which effectively means you can easily implement anemic domain antipatter.
  6. Interceptors - you can do a kind of aspect oriented programming... Like very easily implementing audition, logging, authorization, validation, ect for your domain.
  7. Lucene.NET and NHibernate are well integrated with each other - gives you a very fast and effective implementation of full-text indexing.
  8. It's very mature and popular in enterprise environment.
  9. Big community.

Disadvantages:

  1. Already mentioned learning curve. You can start using NHibernate very fast but it will take you months to master it. I'd highly recomend to read Manning NHibernate book.

  2. Writing XML mapping can be very tedious especially for big databases with hundreds and thousands of tables and views and stored procedures. Yes, there is tools that will help you by generating those mappings but you still will have to do quite a lot of manual work there. Fluent NHibernate seem to simplify this process by getting rid of XML mappings, so is Castle ActiveRecord (AR though is impossible to use for anemic domain as you define mappings in attributes on your model classes).

  3. Performance may be low for certain scenarious. For instance large bulk operations. For those you might have to use IStatelessSession but its awkward experience, least to say...

like image 5
Ray Avatar answered Oct 18 '22 12:10

Ray