As a famous ORM we decided to user nHIbernate with asp.net mvc3. We set up our project in the following way:
NHibernate Repository [contains mappings, service and repositories for nhibernate] MVC3 [this is a UI] Test MVC NHibernate [this is a test project with NUnit]
In above, [] text are written ti make clear about the layers.
Everything is working fine, means all Unit Tests are passed for mapping, insert, update, delete operations. Unfotunately, when we are doing the same operation from our mvc3 application then it threw following error:
"An exception occurred during configuration of persistence layer."
Full stack-trace is as follow:
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\ConfigurationSchema\HibernateConfiguration.cs:line 55 at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\ConfigurationSchema\HibernateConfiguration.cs:line 36 at NHibernate.Cfg.Configuration.Configure(XmlReader textReader) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1511 at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1433 at NHibernate.Cfg.Configuration.Configure(String fileName) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1418 at NHibernate.Cfg.Configuration.Configure() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1404 at examplemvcapp.NHibernateRepository..ctor() in D:\example\examplemvcapp-NHExample\examplemvcapp\NHibernateRepository.cs:line 33 at examplemvcapp_NHExample.UI.Models.CreateAppraisalModel..ctor() in D:\example\examplemvcapp-NHExample\examplemvcapp-NHExample.UI\Models\Department.cs:line 70
Please note that all configuration settings for NHIbernate are same in MVC3 app as in Test project.
Following is the guy where we got the exception :
using (var nhr = new NHibernateRepository()) { this.Departments = nhr.GetAll<Departments>().Select(x => new SelectListItem { Text = x.Departmentdescription, Value = x.Id.ToString() }); }
Above will bring up to following and threw an exception :
public NHibernateRepository() { if (sessionFactory == null) { config = new Configuration(); config.Configure(); config.AddAssembly(typeof(NHibernateRepository).Assembly); sessionFactory = config.BuildSessionFactory(); } Session = sessionFactory.OpenSession(); transaction = Session.BeginTransaction(); Rollback = false; }
The above is working fine in Test project :
using (var nhr = new NHibernateRepository()) { var DeptList = nhr.GetAll<Departments>(); }
Any help in this regard is most appreciable.
Regards
|