PDA

View Full Version : NHibernate and declarative transactions configuration



marika
08-28-2008, 07:45 AM
Hi all,

I've been trying to configure declarative transactions for my web service for couple of days without succeeding. I'm quite new for spring and this is first time I'm trying to use transactions. I have tried to follow the northwind example and read a lots of threads about transactions.

The problem is that when I switch to using TransactionProxyFactoryObject instead of using Spring.Aop.Framework.ProxyFactoryObject I get an ArgumentException: Duplicate type name within an assembly.

I'm using spring version 1.1

Here is my configuration (I've cut n pasted it here but in my code I've divided it in different files as in Northwind example, so there might be some errors due to that):


<httpHandlers>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>
<customErrors mode="Off"/>
</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="SpringWebServiceSupport" verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</handlers>
</system.webServer>

<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
</parsers>

<!-- Proxys -->
<object id="ReportingModuleProxy" singleton="true" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="ProxyTargetType">
<value>false</value>
</property>
<property name="TargetSource">
<object type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop">
<property name="TargetObjectName" value="ReportingModuleTarget" />
</object>
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvice</value>
</list>
</property>
</object>

<!--object id="ReportingModuleFacadeProxy" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="ProxyInterfaces" value="ReportingModule.Common.IReportingModuleFacade"/>
<property name="ProxyTargetType">
<value>false</value>
</property>
<property name="TargetSource">
<object type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop">
<property name="TargetObjectName" value="ReportingModuleFacadeTarget" />
</object>
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvice</value>
</list>
</property>
</object-->

<!-- Plain Objects -->
<object name="ReportingModuleTarget" type="ReportingModule.Application.ReportingModule, ReportingModule.Application" singleton="false"/>
<object name="ReportingModuleFacadeTarget" type="ReportingModule.Business.ReportingModuleFacadeImpl , ReportingModule.Business" singleton="false"/>

<!--Web servicies -->
<object id="Reporting" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="ReportingModuleProxy"/>
<property name="Name" value="ReportingWebService"/>
<property name="Interfaces">
<list>
<value>ReportingModule.Application.IReportingModule, ReportingModule.Application</value>
</list>
</property>
<property name="MemberAttributes">
<dictionary>
<entry key="Test">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Testing the spring configuration."/>
</object>
</entry>
</dictionary>
</property>
</object>

<db:provider id="DbProvider"
provider="OracleClient-2.0"
connectionString="Data Source=xxx;User Id=xxx;Password=xxx;"/>

<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>ReportingModule.Data</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect"
value="NHibernate.Dialect.Oracle9Dialect"/>
<entry key="hibernate.connection.driver_class"
value="NHibernate.Driver.OracleClientDriver"/>
</dictionary>
</property>
</object>

<object id="HibernateTemplate" type="Spring.Data.NHibernate.Generic.HibernateTemplate, Spring.Data.NHibernate12">
<property name="SessionFactory" ref="SessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="CacheQueries" value="true" />
</object>

<object id="HibernateTransactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager , Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="SessionFactory"/>
</object>

<object id="TxProxyConfigurationTemplate" abstract="true"
type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data">
<property name="PlatformTransactionManager" ref="HibernateTransactionManager"/>
<property name="TransactionAttributes">
<name-values>
<add key="Find*" value="PROPAGATION_REQUIRED,readOnly"/>
</name-values>
</property>
</object>

<object name="ReportingModuleFacadeTransactionProxy" parent="TxProxyConfigurationTemplate">
<property name="ProxyInterfaces" value="ReportingModule.Common.IReportingModuleFacade"/>
<property name="Target" ref="ReportingModuleFacadeTarget" />
</object>

<!-- Data Access Objects -->
<object id="TestManager" type="ReportingModule.Data.TestManager, ReportingModule.Data">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
</object>
</objects>
</spring>


In ReportingModule.Application.ReportingModule construction I try to get the ReportingModuleFacadeTransactionProxy from Springs application context. (I know I could/should use dependency injection).

The ReportingModule.Business.ReportingModuleFacadeImpl (the target for the transaction proxy) is my business layer. For the moment it uses only one dao but later on several and therefore I want the transactions on that level.

Thanx
/Marika