Jun 04 2009

Book review: NHibernate in Action

Category: Uncategorizedbengtbe @ 19:39

NHibernate In Action

Authors: Pierre Henri Kuaté, Tobin Harris, Christian Bauer, and Gavin King
Publisher: Manning Publications Co.
Purchase:
Manning, Amazon.com, Amazon.co.uk

Introduction

As part of my goal to learn ORM and NHibernate I purchased the NHibernate in Action book from Manning Publications.
Before I give my conclusion, let’s start with a summary of the different chapters in the book.

1. Object/relation persistence in .NET

This chapter starts the first part of the book, called Discovering ORM with NHibernate. Discusses object persistence, and briefly compares different approaches: hand coding, DataSets, LINQ-to-SQL, NHibernate, and ADO.NET Entity Framework. Describes Object/Relational mapping (ORM), and how it is used to solve the Object/Relational mismatch.

2. Hello NHibernate

Guides you through the process of setting up a project, creating a domain model, setting up the database, creating mapping file, configuring NHibernate, and doing some basic CRUD operations. Takes a high level look at NHibernate, its architecture and how it is configured.

3. Writing and mapping classes

This chapter starts the second part of the book, called NHibernate deep dive. Describes the most common scenarios when mapping a domain model to the database, including important concepts, such as object identity, inheritance, associations, entities vs. value-types, fine-grained object models, and transparent persistence. Finally, it shows three inheritance mapping strategies; table per concrete class, table per class hierarchy, and table per subclass. Covers both XML-mapping and attribute mapping.

4. Working with persistent objects

Describes the three object states (persistent, detached, and transient) that domain models have in a NHibernate application, and how they move from one state to another. It also gives an overview of different ways to get objects out of the database.

5. Transactions, concurrency, and caching

Shows how NHibernate handles transactions, short vs. long conversations, optimistic concurrency control and versioning. Finally it discusses caching and describes the first- and second-level cache that NHibernate provides.

6. Advanced mapping concepts

Goes into detail of more advanced mapping techniques, covering mapping types, custom mapping types, nullable types, enumerated types, collection of value types, mapping of entity associations, and mapping of polymorphic associations.

7. Retrieving objects efficiently

Describes object retrieval with both HQL, Query by Criteria, and native SQL. Topics covered are parameters, comparison operators, logical operators, ordering, joining, report queries, dynamic queries, and query optimization.

8. Developing NHibernate applications

This chapter starts the last part of the book, called NHibernate in the real world. Discusses N-tier development by going through the business, persistence, and presentation layer. Finally it shows how NHibernate can be used to implement audit logging.

9. Writing real-world domain models

Covers domain-model development processes and tools, legacy schema mapping, understanding persistence ignorance, implementing business logic, data binding entities in the GUI, and filling DataSets from entities.

10. Architectural patterns for persistence

Focuses on the design of the persistence layer. Covers designing the persistence layer, implementing reusable Data Access Objects, implementing conversations, and using NHibernate in an Enterprise Services application.

Conclusion

First let’s start with the things that I like about the book. As far as I know it is the only book published about NHibernate, and great OR/M deserves its own book. The book is well written and structured. It covers many aspects of NHibernate, and gives you enough information to start using NHibernate in your own project. The first part of the book is great for beginners of NHibernate. The second part covers more advanced topics and people with some experience with NHibernate should also find something useful in these chapters.

Unfortunately, there are some things that I don’t like about the book. It covers NHibernate 1.2, even though 2.0 was released when the book came out. I also think that the last part of the book covers to much basic stuff about Domain Driven Design and N-tier development, instead of focusing on how to utilize NHibernate. Hopefully, the authors will release a second edition that covers version 2+, and also covers more community project, like Fluent NHibernate.

Overall I give this book 3.5 of 5 stars :)

kick it on DotNetKicks.com Shout it

Tags: ,

2 Responses to “Book review: NHibernate in Action”

  1. Tobin Harris says:

    Hi there, thanks for sharing your thoughts on our book! Agree about NH2.0 coverage and that it should also cover more "fringe" projects like contrib and FNH. Those things are down for the 2nd edition (if/when that happens!)

    Tobin

  2. Jake Scott says:

    Hey nice blog, will subscribe! Ps went to Norway last year to visit a mate in Oslo was cool.

    Cheers
    Jake

Leave a Reply