Hello everyone.
Let me describe the context first:
In a .NET C# project, I use NHibernate to make the link between the C# objects and the database model. I have mapped my objects with NHibernate Mapping Attibutes.
I have written data access queries in HQL, all of them being isolated in individual methods, which are decorated with attributes for transaction management. Here's how my data access classes look like:
namespace MyProject.DataAccess
{
public class ClientDao
{
private ISessionFactory sessionFactory;
public ISessionFactory SessionFactory
{
protected get { return sessionFactory; }
set { sessionFactory = value; }
}
protected ISession CurrentSession
{
get { return sessionFactory.GetCurrentSession(); }
}
[Transaction(TransactionPropagation.Required, IsolationLevel.ReadCommitted)]
public IList<Client> GetAll()
{
return CurrentSession.CreateQuery("from Client c").List<Client>();
}
}
}
I have configured Nhibernate session and transaction management with Spring. Here is the xml configuration:
<!-- NHibernate Configuration -->
<object id="NHibernateSessionFactory" type="GeSuiPro.Abstract.ExtendedSessionFactoryObject, GeSuiPro.Abstract">
...
<property name="HibernateProperties">
...
</property>
<!-- provides integation with Spring's declarative transaction management features -->
<property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>
<!-- Transaction Management Strategy - local database transactions -->
<object id="transactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate21">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="NHibernateSessionFactory"/>
</object>
<tx:attribute-driven transaction-manager="transactionManager"/>
<!-- Exception translation object post processor -->
<object type="Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor, Spring.Data"/>
Now, when I try to access to the session from the C# code, everything works fine:
IList<Client> list = clientDao.GetAll();
However, some calls to the "GetAll" methods are made from the ASP code via ObjectDataSource objects:
<asp:ObjectDataSource ID="odsClient" runat="server" TypeName="MyProject.DataAccess.ClientDao"
SelectMethod="GetAll" DataObjectTypeName="MyProject.Object.Client" />
When accessing to the "CurrentSession" object in my GetAll method, I get the following error : "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here". It seems that something is missing from my configuration.
For information, I use .NET 3.5 Framework with NHibernate 2.1.2. My database is Oracle 11g.
Any help would be appreciated !