Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / XML

Building a Middle Tier Component using NHibernate and Spring.NET

Rate me:
Please Sign up or sign in to vote.
4.50/5 (21 votes)
10 May 2006CPOL8 min read 158.4K   2.4K   109  
Building a highly pluggable middle-tier component with NHibernate and Spring.Net.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   	 <configSections>
   		<sectionGroup name="spring">
			<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
			<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />		
		</sectionGroup>
	        <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
	        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
	</configSections>
	<spring>
		<context>
			<resource uri="config://spring/objects"/>
		</context>
		<objects>	
				
			<object id="mySessionFactory" type="Spring.Orm.Hibernate.LocalSessionFactoryObject, Spring.Orm">
				<property name="MappingResources">
					<list>
						<value>SpringClient.Utility.Product.UProductDTO, SpringClient</value>
					</list>
				</property>
				<property name="ExportSchema" value="true"/>
			</object>	
			
			<object id="myTransactionManager" type="Spring.Orm.Hibernate.HibernateTransactionManager, Spring.Orm">
				<property name="SessionFactory">
					<ref object="mySessionFactory"/>
				</property>
			</object>
		
			
			
			
			<!-- UProduct Hibernate+ Spring conf -->
			<object id="UProductTarget" type="SpringClient.Utility.Product.UProductServiceImpl, SpringClient">				
				<property name="ProductDAO">
					<ref object="ProductDAO"/>
				</property>
			</object>		
			
			<object id="UProductService" type="Spring.Transaction.Interceptor.TransactionProxyFactoryObject, Spring.Orm">
				<property name="TransactionManager">
					<ref object="myTransactionManager"/>
				</property>
				<property name="Target">
					<ref object="UProductTarget"/>
				</property>
				<property name="TransactionAttributes">
					<name-values>
						<add key="Save*" value="PROPAGATION_REQUIRES_NEW"/>
						<add key="Update*" value="PROPAGATION_REQUIRED"/>
						<add key="Delete*" value="PROPAGATION_REQUIRED"/>
					</name-values>
				</property>
			</object>

			<object id="ProductDAO" type="SpringClient.Utility.Product.UProductDAO, SpringClient">
				<property name="SessionFactory">
					<ref object="mySessionFactory"/>
				</property>
			</object>			
						
		</objects>
	</spring>	
	<nhibernate>
		<add key="hibernate.show_sql" value="true"/>
		<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
		<!--
		<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
		<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
		<add key="hibernate.connection.connection_string" value="Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI" />
		-->		
		<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->		
		<add key="hibernate.dialect" value="NHibernate.Dialect.Oracle9Dialect" />
		<add key="hibernate.connection.driver_class" value="NHibernate.Driver.OracleClientDriver" />		
		<add key="hibernate.connection.connection_string" value="Data Source=ihis;User ID=system;Password=manager;" />		
	</nhibernate>
	<!-- This section contains the log4net configuration settings -->
	<log4net>
		<!-- Define some output appenders -->	
		<appender name="rollingFile" type="log4net.Appender.ConsoleAppender,log4net" >			
			<param name="File" value="log.txt" />
			<param name="AppendToFile" value="true" />
			<param name="RollingStyle" value="Date" />
			<param name="DatePattern" value="yyyy.MM.dd" />
			<param name="StaticLogFileName" value="true" />
			<layout type="log4net.Layout.PatternLayout,log4net">
				<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
			</layout>
		</appender>
		<!-- Setup the root category, add the appenders and set the default priority -->		
		<root>
			<priority value="DEBUG" />
			<appender-ref ref="rollingFile" />
		</root>
	</log4net>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Netherlands Netherlands
Engineer Powered by the Cloud

Comments and Discussions