Fluent NHibernate - An exception occurred while setting up a save layer

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

Below is the configuration code in which I get the error:

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

But when NHibernate tries to configure, I get an error while posting:

An exception occurred while setting the save level.

An internal exception says:

ProxyFactoryFactory has not been configured. Initialize the 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 that I found, I made the following changes:

  • Add the following DLLs to my application box:

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

  • Added follwing property in hibernate.cfg.xml

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

But still I get the same exception.

+7
c # nhibernate configuration fluent-nhibernate
source share
10 answers

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

The display should start as follows:

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

Along with the error you post, perhaps additional information is provided as this error is quite common for the configuration analyzer. If not, perhaps you can provide more details about your hibernate.cfg.xml.

+1
source share

I also had this error. It starts when you do not copy the mapping file (hibernate.cfg.xml) to the assembly directory.

Decision:

  • In Solution Explorer, right-click in the mapping file ( hibernate.cfg.xml ), select Properties , then make sure Copy to output directory . Copy if new ).
+14
source share

As Alex InTechno said, it could be a mistake in defining your mapping files or in mapped objects. I experienced the same error when I forgot that all properties in the mapped classes should be defined as virtual.

 public String Name {get;set;} public virtual String Name { get; set; } 
+5
source share

Exception with text PotentialReasons

* The database was not configured using the database method.

can also be called by the FluentConfiguration.BuildConfiguration () method in case of incorrect mappings (i.e. * Classes of classes have not been successfully analyzed), and you did not configure the database using the .Database () method. It is a little vague that it was discovered only at the stage of building the configuration, and not when these classes are added from the assembly (via AddFromAssemblyOf <>)

You can check if your classes * Maps were successfully converted to HBM by running the line m.FluentMappings.Add (TypeOf (YourMappedTypeMap)) ExportTo (@ "C: \ Temp \ fluentmaps").)

+1
source share

I had the same issue with NUnit tests in Resharper 8.1

Check "ReSharper | Options | Tools | Unit Testing | Use a separate version of AppDomain for each build with tests", fixed it

+1
source share

Well, I was able to solve this error by placing the .cfg.xml file in the bin of call app.

But now I get another error: - (

FluentNHibernate.Cfg.FluentConfigurationException was unhandled Message: An incorrect or incomplete configuration was used to create the SessionFactory. See the PotentialReasons and InnerException collection for more information.

* The database was not configured using the 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?

0
source share

Trying to set up the database in App.config and mappings via Fluent NHibernate, I also received a FluentNHibernateException message

  • The database was not configured using the database method.

The link for displaying information was deactivated, so I could not get additional information. For several hours, I found out that there was an error in my connection string ("pasword = xyz;" instead of "password = xyz;")

0
source share

Try setting the modifier protected in set_id and set_sampelList. eg:

 public virtual int Id { get; protected set; } 

and

 public virtual IList<Store> StoresStockedIn { get; protected set; } 
0
source share

I'm starting to get

* The database was not configured using the database method.

when trying to connect to a DB / 2 database without making any changes to my code. After checking that the configuration file is copied to the assembly directory and verifies that my XML was well-formed and consistent with version 2.2, I finally went to check the database to make sure that nothing had changed.

It turned out that the password for the connected account has expired. It was not invalid and was not active in the account - the password was simply expired. I'm not sure why the expired password showed up in such an odd error message.

0
source share

It seems that this error can be a bunch of different things. I got the same error and eventually realized that this was because I had excluded the unused view and display from the project. I don’t know how this caused the error, but as soon as I added it, the error disappeared.

0
source share

All Articles