NHibernate Serialized startup

In all of my NHibernate implementations I serialize the startup. It saves a noticeable amount of time. We know that without it, NHibernate validates all the mapping files each time we start the program. If we only have 1 or 2 simple files it is not a problem, however, if you have a large implementation, you need to serialize.

I implemented the common method using the System.Runtime.Serialization.Formatters.Binary class with reflection to create and validate the correct version of the configuration file.

An odd thing happened when I was pointing my program from Microsoft SQL Server to Oracle. It continued to access SQL Server.

My implementation of serialization compared the date of my NHibernate class library which contained my mapped objects with the date of the serialized file. I didn’t implement any logic to confirm database changes.

I wanted to note this down so that if you experience it, hopefully you will not spend so much time troubleshooting as I did.

To view how to implement serialization, you can buy my book here. It gives a detailed example of serializing the NHibernate startup.