I found some tip from Spring.NET + NHibernate - Multiple (Distinct) Databases with OpenSessionInView, but it dosen't work for me, need your help to identify what's going wrong.
my project is based on ASP.NET/Spring.NET(OpenSessionInView)/NHibernate, and we need to manupilate an external database, so we want to support multi datasources in OSIV pattern.
what we have done by ref the above links:
(1) Create a subclass of Spring.Data.NHibernate.Support.OpenSessionInViewModule
namespace MyProject.Infrastructure.NHibernate
{
public class ExtDbOpenSessionInViewModule : OpenSessionInViewModule
{
}
}
(2) Confige the OSIV in web.config
here is my configurations for Spring.NET and NHibernate integration:
<!-- Spring Web Support and OSIV for NHibernate -->
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInViewOnLocalDb" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32"/>
<add name="OpenSessionInViewOnExtDb" type="MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule, MyProject.Infrastructure"/>
<!-- NHibernate SessionFactory in OSIV-->
<appSettings>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="LocalDbSessionFactory"/>
<add key="MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule.SessionFactoryObjectName" value="ExtDbSessionFactory"/>
</appSettings>
When we were running it, the system says:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
we found that SessionFactoryObject in any Repository object is null.
the logs was like these:
2012-09-13 10:29:19,017 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Trying to close SessionScope 2012-09-13 10:29:19,018 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Only participated Hibernate Session - doing nothing 2012-09-13 10:29:19,030 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Participating in existing Hibernate SessionFactory 2012-09-13 10:29:19,033 [14] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Participating in existing Hibernate SessionFactory 2012-09-13 10:29:19,043 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Trying to close SessionScope 2012-09-13 10:29:19,055 [14] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Trying to close SessionScope 2012-09-13 10:29:19,062 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Only participated Hibernate Session - doing nothing 2012-09-13 10:29:19,071 [14] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Only participated Hibernate Session - doing nothing 2012-09-13 10:29:19,117 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Participating in existing Hibernate SessionFactory 2012-09-13 10:29:19,122 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Trying to close SessionScope 2012-09-13 10:29:19,126 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Only participated Hibernate Session - doing nothing 2012-09-13 10:29:19,130 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Participating in existing Hibernate SessionFactory 2012-09-13 10:29:19,132 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Trying to close SessionScope 2012-09-13 10:29:19,132 [13] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Only participated Hibernate Session - doing nothing 2012-09-13 10:29:21,347 [14] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Participating in existing Hibernate SessionFactory 2012-09-13 10:29:21,441 [14] INFO Spring.Aop.Framework.AutoProxy.InfrastructureAdvisorAutoProxyCreator [(null)] - Candidate advisor [ObjectFactoryTransactionAttributeSourceAdvisor: advice object 'Spring.Transaction.Interceptor.TransactionInterceptor#0'] rejected for targetType [ASP.pages_sysmgmt_debug_aspx] 2012-09-13 10:29:21,457 [14] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Trying to close SessionScope 2012-09-13 10:29:21,458 [14] DEBUG MyProject.Infrastructure.NHibernate.ExtDbOpenSessionInViewModule [(null)] - Only participated Hibernate Session - doing nothing
Oops! we are realy stuck by it.