views:

1792

answers:

4

Hello there,

I am using Fluent NHibernate with an external 'hibernate.cfg.xml' file.

Following is the configuration code where I am getting error:

       var configuration = new Configuration();
       configuration.Configure();

       _sessionFactory = Fluently.Configure(configuration)
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Template>())
                .BuildSessionFactory();

        return _sessionFactory;

But When NHibernate is trying to configure, I am getting floowing error:

An exception occurred during configuration of persistence layer.

Please help.

+1  A: 

The problem might be in your hibernate.cfg.xml, double check that is using 2.2 version and if well formed.

The mapping should start like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

Along with the error you post, maybe more information is supplied because that error is quite generic to the configuration parser. If not, maybe you can give more details of your hibernate.cfg.xml.

Marc Climent
A: 

Well, I was able to resolve that error by placing .cfg.xml file in bin of calling app.

But now, I am getting another error :-(

FluentNHibernate.Cfg.FluentConfigurationException was unhandled Message: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

* Database was not configured through Database method.

Here is my hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=dev\sql2005;Initial Catalog=TestDB;Integrated Security=True</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

Any thoughts?

inutan
Check the InnerException.
James Gregory
+1 to James. Keep running down the Exceptinn tree until you find something useful.
Richard Szalay
+1 to James. I was having this error and looked at the InnerException to find that a named connection string was not being found, and realized my test project's App.config was missing the connection string that was in my web app's Web.config.
Chris F
+1  A: 

Thank you for all the tips. The Inner exception says:

The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.

I googled and according to some solutions I found, I have made following changes:

  1. Add following dlls to my app bin:

    Castle.Core.dll, Castle.DynamicProxy2.dll, NHibernate.ByteCode.Castle.dll

  2. Added follwing property in hibernate.cfg.xml

    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>

But still I am getting the same exception :-(.

Please help.

inutan
added the castle dlls (Castle.Core.dll, Castle.DynamicProxy2.dll, NHibernate.ByteCode.Castle.dll) to my calling app. Bin folder and it is working fine :-). Thanks to all for help.
inutan
A: 

Hello inutan ! I've error too, and I fix it follow some step:

Error fire when You don't copy mapping file (hibernate.cfg.xml) to Build directory.

Solution:

  • In Solution explorer: Right Click on mapping file (hibernate.cfg.xml), choose Properties, At here, see Copy To Out Directory (you sure select Copy if newer).

Good Luck !

To All Friend: I'm VietNamese, so, i can have some eng grammar error, but i will try learn more... Thank for all.

Best regard, kkmct

kkmct