Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6931293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:33:30+00:00 2026-05-27T11:33:30+00:00

The HBM export function in Fluent NHibernate does not seem to work. If I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:33:30+00:00Added an answer on May 27, 2026 at 11:33 am

    After drilling through the Fluent source code (latest from Git repository), something looks odd to me.

    The ExportTo() methods are defined twice – once by FluentConfiguration itself, and it does appear it’s exporting the configuration files “too soon”, resulting in an incomplete configuration, both at run-time (resulting in the above exception) and at export-time.

    Oddly, the PersistenceModel type does have the capability to export the complete configuration, but this feature is not exposed. Instead, there are at least two other seemingly broken implementations of ExportTo().

    To solve the problem, we need access to the PersistenceModel instance, which has the capability to write the complete configuration – fortunately, I found a way to do that:

            // create a local instance of the PersistenceModel type:
            PersistenceModel model = new PersistenceModel();
    
            FluentConfiguration config = Fluently.Configure()
                .Database(database)
                .Mappings(m => m.UsePersistenceModel(model) // use the local instance!
                                   .FluentMappings.AddFromAssemblyOf<Entity>()
                                   .Conventions.AddFromAssemblyOf<Entity>());
    
            // ...
    
            var path = Service.Config.HbmExportPath;
    
            _sessionFactory = config.BuildSessionFactory(); // completes the configuration
    
            // now write out the full mappings from the PersistenceModel:
    
            if (!String.IsNullOrEmpty(path))
                model.WriteMappingsTo(path);
    

    The HBM files are now being output correctly!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to switch out .hbm mappings to fluent mappings and have a problem
Here's a starter list: if hbm is hand generated, is it an embedded resource?
I'm looking for a NHibernate Mapping generator which could generate a mapping file (hbm)
I have an Nhibernate hbm that maps a many to many relationship. For database
I have the following XML (.hbm): <property name=Geometry column=the_geom> <type name=NHibernate.Spatial.Type.GeometryType,NHibernate.Spatial> <param name=subtype>MULTIPOLYGON</param> <param
A recent release of Fluent Nhibernate (1.1) now supports stored procedures. I was wondering
I've the AnagraficaBase hbm file: <?xml version=1.0 encoding=utf-8?> <hibernate-mapping xmlns=urn:nhibernate-mapping-2.2> <class entity-name=AnagraficaBase table=anagrafica> <id
This is the basic example from hbm-style nhibernate. http://ayende.com/blog/2327/multi-table-entities-in-nhibernate public class Person { public
Does anyone know a way to intercept the call Hibernate will make to instantiate
We are using NHibernate in our project and need all .hbm.xml files to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.