The HBM export function in Fluent NHibernate does not seem to work.
If I call FluentMappingsContainer.ExportTo, the generated mappings come out incorrect, and I get the following exception:
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
My configuration code looks like this:
MsSqlConfiguration database = MsSqlConfiguration.MsSql2008
.ConnectionString(GetConnectionString())
.Cache(c => c
.UseQueryCache()
.UseSecondLevelCache()
.ProviderClass<SysCacheProvider>()
);
database.ShowSql();
FluentConfiguration config = Fluently.Configure()
.Database(database)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entity>()
.Conventions.AddFromAssemblyOf<Entity>());
config.ExposeConfiguration(x =>
{
x.SetProperty("hbm2ddl.keywords", "auto-quote");
x.SetInterceptor(new ServiceInterceptor());
});
config.ExposeConfiguration(x => { x.SetProperty("current_session_context_class", "thread_static"); });
// Configure HBM export path, if configured:
var path = Service.Config.HbmExportPath;
if (!String.IsNullOrEmpty(path))
config.Mappings(m => m.FluentMappings.ExportTo(path));
// Build session factory:
_sessionFactory = config.BuildSessionFactory();
Setting HbmExportPath in my configuration to null, app launches and runs without problems. As soon as I configure the export path (causing ExportTo to be called), the generated mappings cause an exception as described above.
Looking at the exported mappings, it appears my conventions are not being applied - for example, I have a foreign-key convention in place, using camel-case and "Id" suffix, but when I export the HBM files, primary keys are consistently named with an underscore and lowercase "_id", for example:
<class xmlns="urn:nhibernate-mapping-2.2" name="MyApp.Entities.Contact, MyApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Contact`">
...
<bag name="Departments" table="ContactDepartment">
<key>
<column name="Contact_id" />
</key>
<many-to-many class="MyApp.Entities.Department, MyApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Department_id" />
</many-to-many>
</bag>
...
</class>
I had this problem with the previous version and with the current release of Fluent.
Any ideas?