Review: NHibernate in Action

Cover of NHibernate in Action

Authors: Pierre Henri Kuaté, Tobin Harris, Christian Bauer, Gavin King
Publisher: Manning
Published: 2009
Pages: 367

NHibernate is an Object/Relational Mapper (ORM) for .NET applications. It is a complex tool, and trying to piece together useful information gleaned from the web has been frustrating. So I decided to pick up this book.

The first chapter introduces the concept of object/relational persistence, compares various data-handling techniques in .NET, and finally introduces NHibernate, showing how it solves the persistence problem described earlier.

The second chapter is aptly titled “Hello NHibernate!” and, in the time-honoured tradition of books about programming, constructs a basic application using NHibernate. This quite nicely shows what is involved when using NHibernate, at least on the surface. Detailed coverage is provided later in the book, of course, but this chapter is enough to get one started.

The middle chapters of the book dig into NHibernate workings in detail. XML mapping files are heavily discussed, since they are the primary means to map entities to the data store. We see how to make non-persistent objects persistent, and how to do the reverse as well. Less obvious behind-the-scenes details are covered, including transactions, caching, and lazy and eager loading. There is some coverage of advanced mapping concepts, where a domain or data store are complex enough to require some less-common mapping techniques. Finally, the book shows how to assert control over how NHibernate works by using the Criteria API, and writing HQL or even straight SQL.

The final three chapters of the book discuss application domain and architecture, and collectively show how NHibernate fits in. I found this higher-level discussion quite helpful since it made some pieces click into place.

After having finished the book, my head is swimming. The information was detailed, dense, and deep. I feel I now have enough of a grip on NHibernate to use it on a small project – just the basics. If that goes well, I will try to do the same with a larger project, applying the advanced concepts where possible.

An issue with this book is that it was outdated as soon as it was published. The book was written for NHibernate 1.2, but ran into delays during the process. By the time it was finally published, NHibernate 2.0 had been released. What I have gathered is that the book is still largely useful, since it covers details that are unlikely to change, which somewhat mitigates the issue. Not to mention that it is the only book – that I know of – on the subject.

This book will be a fixture on my desk when I use NHibernate. I will be referring to it a lot!

The bottom line: This book thoroughly covers NHibernate and gives you enough information to get started, including details on various aspects of the tool as well as larger architectural considerations for your projects. It’s heavy reading, but all the necessary details seem to be there. It is also slightly outdated, but is still relevant. Plus the fact it seems to be the only book on the subject makes it a winner.