I understand that spring can manage your sessions for you, if configured like so:
<object name="SessionFactory"
type="MyApp.DAL.DAOs.SessionFactoryObject, Leverate.Crm.CrmService.DAL">
<!--My class which inherits from LocalSessionFactoryObject and defines the mapping assemblies to be used-->
<property name="ExposeTransactionAwareSessionFactory" value="true" />
<property name="DbProvider" ref="DbProvider"/>
<property name="HibernateProperties">
<dictionary>
<entry key="cache.use_second_level_cache" value="false"/>
<entry key="command_timeout" value="180"/>
<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="SchemaUpdate" value="false"/>
</object>
<db:provider id="DbProvider"
provider="SqlServer-1.1"
connectionString="Data Source=local;Initial Catalog=northwind;Trusted_Connection=Yes;"/>
problem is, that using SessionFactory.GetCurrentSession() throws a 'No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here' exception.
I saw some answers saying that in web context you have to use openSessionInView (or some such) httpModule. But what do you do in a console app (or windows service, for that matter)?
You are exposing your session factory as a transaction aware session factory, which implies sessions are managed for you by Spring for all Methods that are correctly wrapped in a transaction. For wrapping your data access methods in a transaction with spring, you can use a declarative (attribute driven) or programmatic approach.