NHibernate in Action – Book Review

Book on Amazon
All summer I meant to read the book “NHibernate In Action”. I finally got around to it, better late than never I guess. In my opinion this book is aimed at higher level programmers such as lead developers or architects. The book does not contain clear step by step examples of how to get NHibernate running. However it does provide in depth conceptual reasoning why anyone would want to use NHibernate along with reference style examples. If you are trying to learn NHibernate you are better off reading a few online tutorials first and after that read this book so you can understand exactly what NHibernate is doing and how it does it. Below are some book pros & cons, NHibernate links, and chapter summaries.
Pros
- Examples are all in c#
- Shows config examples for NHibernate 1.2.1 and 2
- Promotes proper design patters often references popular pattern books
- Makes note of minor current bugs or missing features that may cause issues or confusion
- Provides suggestions for when to use something other than the default NHibernate settings
- Mentions how NHibernate can use the features of multiple RDMS, not just SQL Server
Cons
- Download and install instructions were vague
- I downloaded NHibernate 2.1.0 QA from SourceForge after finally finding the link on nhforge.org. From there I followed the install notes in the downloaded zip file.
- Examples do not use Generics
- Doesn’t provide a link or even a suggestion to where you can download the NHibernate.Mapping.Attributes library which lets you use features similar to the annotations in Hibernate 3
- I found them here: http://sourceforge.net/projects/nhcontrib/files/NHibernate.Mapping.Attributes/
- Shows attribute and xml mapping examples randomly. In my opinion it would be better if one or the other was used consistently.
- Jumps from definitions to examples. No clear step by step examples
- I would say this book is more of a reference than tutorial
Helpful NHibernate Links
- NHibernate community site
- NHibernate Google Group
- Stackoverflow NHibernate questions and answers
- How to use MySQL with .NET
- Databases supported by NHibernate
- Common exceptions
Chapter 1
- Basic definitions of persistence, sql(sql not sql server) databases, and layered development
- Doesn’t mention the testability benefits of layered development
- Compares persistence layer choices available with .Net
- Makes the case that LINQ and Entity framework will not replace NHibernate
- Definition of ORM
- Addresses the performance concerns of using ORMs
- Author tries to convince people to use ORMs, this part needs a little salesman ship but I guess if someone is open minded enough to read this book then they don’t need much of a sales pitch.
Chapter 2
- Some basoc instructions for how to download and install the NHibernate dll
- con: Could use a little details in this section about how to use the versions that don’t have msi installers yet like the 2.1.0.GA release I downloaded.
- Shows very simple examples of saving and loading an entity
- Then shows you a basic xml mapping document
- o Shows a mapping document for versions 1.2 and 2.
- Quick glance at the NHibernate api and in depth notes on important interfaces
- Very short section on logging with log4net
Chapter 3
- Good section on the benefits of having a transparent persistence layer
- Discusses the anti xml config file movement.
- However doesn’t mention the fact that poorly designed and overly complicated schemas are one reason for the back lash. Also never mentions CoC.
- Discusses using attributes as meta data
- IMHO way more time should have been spent telling the users how to setup/install the mapping dlls needed to use this feature
- Does show many examples of how to use the attributes and what the xml version of the meta data would look like
- This chapter provides information about the hibernate mapping elements and options
- It is a mix between a reference and tutorial.
- Good section on object identity vs equality
- con:Â Gives an explanation of what primary keys are. Surely anyone reading this book knows already knows what primary keys are.
- Good short explanation of the different types of primary key creation that NHibernate supports
- Long discussion on database and object model design
- table per concrete class
- table per sub class
- table per class hierarchy
Chapter 4
- Explains object identity scope. probably a little high level for low level developers
- Explains different options for Equals and HashCode implementations
- Automatic dirty checking
- Changing an object in an ISession and committing will result in those changes being automatically reflected in the database
- Clearly denotes the different cascading persistence options
- Details the different object retrieval options
- Retrieving by identifier
- HQL
- NHibernate Criteria API
- Native SQL queries
- In depth discussion of fetching strategies and how to implement each one
- Short section on batching and how it can speed up queries for selecting collections
- Provides common sense ideas for analyzing NHibernate’s performance
Chapter 5
- Background on database transactions, unit of work and conversations
- Excellent section on transaction isolation
- Background on ORM caching
Chapter 6
- Starts with more definitions and comparisons of entities and value types
- Nice chart showing how NHibernate mapping types relate to .Net types
- Give in depth example of creating a custom mapping type
- Nice tips on controlling collection sorting with mapping settings
Related Posts
Comments
5 Responses to “NHibernate in Action – Book Review”
Leave a Reply
- it does not cover :
- fluent NHibernate
- LINQ to NHibernate
- NHibernate validation lib.
and many other recent changes in the library.
@anon – Those are excellent points. I still think any book about a valuable open source project is a good thing. Like my post says I recomend this book, but it’s not a complete guide to nhibernate. Hopefully the next nhib book will fill in the gaps.
You made some good points here.
I totally agree! I was pretty disapointen, not knowing anything about ORM framework and my first glance att NHibernate and after a couple of chapters I was totally lost. This is not a tutorial.
[...] post: NHibernate in Action – Book Review : Code Hangover By admin | category: code review | tags: aimed-at-higher, better-never, book, [...]