NHibernate 3.0 Cookbook Review

Once again, Packt Publishing offered me a chance to review one of their books; this time, it was NHibernate 3.0 Cookbook. I must say I liked what I read.

The book was written by Jason Dentler, has 328 pages, some of its technical reviewers are well known in the NHibernate community (Fabio Maulo, Jose F. Romaniello, Gabriel Nicolas Schenker, Tuna Toksoz) and is divided into 8 chapters plus an appendix, which you can find here.

It is not a beginner's book, some basic topics are not covered, ID generators coming to my mind. It follows a now classic cookbook style, where each chapter contains a list of recipes. These range from basic to slightly more advanced, none is what I'd call advanced. Each chapter is sequenced naturally, the more basic coming in first. I like the fact that the book doesn't cover only the NHibernate library, but also some of it's most useful sidekicks: for example, the chapter on Models and Mappings covers not only XML mappings but also FluentNHibernate and also ConfORM. However, I don't like the fact that it is based on SQL Server 2008, I think the author should have tried to, at least, support Oracle. Each recipe starts with a use case and then goes on to a (not detailed, which is fine, since this is not for beginners) explanation on how to achieve it.

The first chapter, Models and Mappings, covers regular mappings, with or without a base class, with XML, FluentNHibernate and ConfORM mappings, components and versioning. It is OK, but I feel, for example, that the recipe Handling versioning and concurrency could have described other forms of versioning, such as datetime-based, SQL Server's TIMESTAMP/ROWVERSION or Oracle's ORA_ROWSCN.

Next comes the Configuration and Schema chapter. Nothing to say here, I think it does a good job, covering configuration by code, XML, FluentNHibernate and ConfORM also. It explains how to set up Log4Net and how to generate and script the database using NHibernate Schema Tool.

Chapter 3, Sessions and Transactions, covers basic session-factory and session-related operations, with particular enphasis on web applications (both ASP.NET WebForms and MVC are discussed). Stateless sessions are also covered as well as the less known EntityMode.Map, which, IMO, is very interesting. Some session advanced topics are missing though, for example, Evict is barely mentioned. It provides good guidance on integrating TransactionScope with NHibernate's native (and required) transactions, and also on using uNHAddins' Conversation per Business Transaction functionality.

The chapter on Queries comes in forth, and mostly covers everything, from QueryOver to Criteria API, including LINQ and HQL. MultiCriteria, MutiQuery and Futures are also discussed. All of these APIs leave a lot to be said, which is understandable because these are vast subjects.

Then comes Testing. NHibernate Profiler is presented first and the rest of the recipes rely on NUnit. The classic ghostbuster test is shown as well as the FluentNHibernate Tester, to check for invalid FluentNHibernate mappings.

Chapter 6 is called Data Access Layer. It it several wrapping techniques for NHibernate are presented, such as an implementation of the Repository Pattern for NHibernate and classic paging techniques with. Last comes integration with LINQ Specifications to allow for fine-grained querying of our model based on LINQ predicates, which is interesting.

The next chapter, 7, Extending NHibernate, contains the most advanced repices. These include using Dependency Injection containers, using event listeners and custom user types and an interesting recipe on overriding the default connection provider to allow dynamic connection strings.

The final chapter (8) talks about NHibernate Contribution Projects: NHContrib. Specifically, validation (NHibernate Validation), other 2nd level cache providers (NHibernate Caches), full text search (NHibernate Search: integration with Lucene.NET), database sharding (NHibernate Shards), persistent conversations (NHibernate Burrows) and spatial data support (NHibernate Spatial) is covered, which are some of the most used NHibernate libraries.

The book ends with an appendix where, by topic, we are referenced to the appropriate recipes. Topics are divided in ASP.NET WebForms, ASP.NET MVC and Windows Forms.

In conclusion, I liked this book. I think it is a welcome addition to the NHibernate library, once again by Packt Publishing (where are the others?). It lacks some advanced concepts, but it does a good job presenting it's solutions. Some, however, could be better explained, and at least Oracle should also be mentioned.

Bookmark and Share

                             

1 Comment

Comments have been disabled for this content.