So, what's the problem with NHibernate ?

First, let me say that NHibernate is great tool. Really.
We use it since years, and it is very, very, very useful.

To seamlessly handle persistence information, it uses "instrumentation" mechanism, using libraries such as Castle (among others). The goal of this is to add some needed persistence information to your Model class, such as the associated session, the dirty state of the object and so on...
Similar things are done with collections, by substituting classic implementations (based on interfaces, such as IList, IDictionary,...) with persistent aware ones.

And it works great... until you need to send them outside the Microsoft Virtual Machine!
It can be as simple as trying to save your persistent instance into a XML file, or send it through WCF. In fact, problem come when you need to serialize your persistent data, because the serialization mechanism does not expect class to have been instrumented, and to handle NHibernate session life cycle.

Common Serialization issues

Serializing persistent entities lead to various exception message or unexpected/unwanted behavior:
* LazyInitializationException : when the serializer tries to access unloaded associations and the NHibernate session is closed
* Eager-fetching : if the current session is not closed, the serialization mechanism will load the entire object graph by calling each property getter (with very bad performances because of the uderlying lazy loading mechanism)
Etc...

The NGilead solution

The idea behind NGilead is very simple: transform persistent entities back to simple Plain Old C# Object (POCO), by removing code instrumentation and replacing persistent collections with their regular counterpart.

Simple does not mean easy!

You cannot remove persistent information (stored in instrumentation) and expect NHibernate to work properly without it.
NGilead has to store the persistent information before "neutralizing" persistent entities (the clone operation), and put it back when the object is sent back to NHibernate (merge operation). NGilead allows you to store this (simplified) information on the POCO itself or on server (in a future release).

Last edited Mar 27, 2010 at 8:48 PM by bmarchesson, version 1

Comments

No comments yet.