I am trying to use spring.net and nihibernate for my data layer.
I have a simple DAO object that includes the following code:
[Transaction] public long Save(Request entity) { return (long)CurrentSession.Save(entity); }
Whenever this code is called, I get the following error:
"The Hibernate session is not thread-related, and the configuration does not allow the creation of non-transactional files here."
My DAO layer has the following configuration, which my web.config refers to:
<?xml version="1.0" encoding="utf-8" ?> <objects xmlns="http://www.springframework.net" xmlns:tx="http://www.springframework.net/tx" xmlns:db="http://www.springframework.net/database" xmlns:aop="http://www.springframework.net/aop" > <description> The Northwind object definitions for the Data Access Objects. </description> <object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core"> <property name="ConfigSections" value="databaseSettings"/> </object> <db:provider id="DbProvider" provider="SqlServer-2.0" connectionString="Data Source=ME-LT;Initial Catalog=SupplyAndDemand;Integrated Security=True"/> <object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate21"> <property name="DbProvider" ref="DbProvider"/> <property name="MappingAssemblies"> <list> <value>SAD.Providers.NHibernate</value> </list> </property> <property name="HibernateProperties"> <dictionary> <entry key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <entry key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/> <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> </dictionary> </property> <property name="ExposeTransactionAwareSessionFactory" value="true" /> </object> <object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate21"> <property name="DbProvider" ref="DbProvider"/> <property name="SessionFactory" ref="NHibernateSessionFactory"/> </object> <object id="RequestDao" type="SAD.Providers.Nhibernate.NHibernateRequestDao, SAD.Providers.Nhibernate"> <property name="SessionFactory" ref="NHibernateSessionFactory" /> </object> <tx:attribute-driven transaction-manager="transactionManager"/> </objects>
In my web.config, I have included a parser link:
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data"/>
and refers to my dao.xml as an assembly resource.
This DOA is injected into another configured spring object from which Save is called.
Any ideas what I'm doing wrong? As you can see, I turn on the configuration
<tx:attribute-driven transaction-manager="transactionManager"/>
I am bound to spring code and put the breakpoint in the invoke TransactionInterceptor method - it is never called - so maybe the proxy is not created for my dao objects?
Here is the full stack trace:
<StackTrace><![CDATA[at Spring.Data.NHibernate.SpringSessionContext.CurrentSession() in F:\Spring.NET\Spring.NET\src\Spring\Spring.Data.NHibernate12\Data\NHibernate\SpringSessionContext.cs:line 70 at NHibernate.Impl.SessionFactoryImpl.GetCurrentSession() at sad.Providers.Nhibernate.NHibernateDao.get_CurrentSession() in F:\PersonnalProjects\sad\trunk\src\sad\sad.Providers.Nhibernate\nHibernateDao.cs:line 29 at sad.Providers.Nhibernate.NHibernateRequestDao.Save(Request entity) in F:\PersonnalProjects\sad\trunk\src\sad\sad.Providers.Nhibernate\NHibernateRequestDao.cs:line 41 at sad.Messaging.RequestManager.RequestManager.ProcessRequest(UserCredentials userCredentials, Request request) in F:\PersonnalProjects\sad\trunk\src\sad\sad.Messaging.RequestManager\RequestManager.cs:line 39 at sad.Messaging.UI.Web.RequestManagerService.ProcessRequest(UserCredentials userCredentials, Request request) in F:\PersonnalProjects\sad\trunk\src\sad\sad.Messaging.UI.Web\RequestManagerService.cs:line 28 at requestManagerService.ProcessRequest(UserCredentials userCredentials, Request request) at SyncInvokeProcessRequest(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)