These are the show-stoppers for me for quite a while. I was using the example from the book trying to replace App.config (in my case Web.config) with hibernate.cfg.xml so I can have different configuration in a test project, but these two guys kept showing up.
The “dialect thing” actually tells us that hibernate.cfg.xml has not been processed at all, and it probably also made interpretation of the mapping file impossible as well.
Good thing was that I made sure that mapping works with .config file so I’ve had no doubt in my .hbm.xml files. But it was also a bad thing because it left me with no idea where to look for the problem.
Finally, here are the two common reasons for NHibernate to fail this way:
1. Configuration.Configure() must be called in order for hibernate.cfg.xml to be loaded. That is not the case with .config option.
2. Unlike .hbm.xml files which are deployed as “Embedded Resource”, .cfg.xml must be deployed as “Content” and copied to the output.
Configure.AddAssembly() method only tells NHibernate where to look for the .hbm.xml files (as resources), and has nothing to do with configuration of NHibernate itself. Since my test project compiled into another assembly, I’ve had to tell NHibernate where my mappings are located:
... <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver </property> <mapping assembly="[My Assembly]" /> ...
Finally, everything appears to be working.