NHibernate “Could not find the dialect in the configuration” “Could not compile the mapping document”

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">
<mapping assembly="[My Assembly]" />

Finally, everything appears to be working.

This entry was posted in Software Development, Tools and tagged , , . Bookmark the permalink.

3 Responses to NHibernate “Could not find the dialect in the configuration” “Could not compile the mapping document”

  1. v. says:

    Regarding the point 2. – such deployment method actually makes sense, as .cfg.xml file is likely to contain an instance-specific connection string which is not possible to change inside the assembly.

  2. mak says:

    l have the config in the file classe and i had this error Configuration cfg = new Configuration();
    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, “Nhibernate.Connection.DriverConnexionProvider”);
    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, “NHibernate.Dialect.Oracle10gDialect”);
    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, “NHibernate.Driver.OracleClientDriver”);
    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ” User ID=system;Password=sepret;Data Source=sepret”);
    cfg.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, “NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle”);
    m_SessionFactory = cfg.BuildSessionFactory();
    ISession session = null;
    : Could not find the dialect in the configuration
    plz i need help

  3. v. says:

    Well, in your case – it appears that you actually did not configure the dialect

    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, “NHibernate.Dialect.Oracle10gDialect”);

    should have been:

    cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, “NHibernate.Dialect.Oracle10gDialect”);

Leave a Reply

Your email address will not be published. Required fields are marked *