Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3302100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:49:02+00:00 2026-05-17T20:49:02+00:00

Let me describe the context first: In a .NET C# project, I use NHibernate

  • 0

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 !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:49:03+00:00Added an answer on May 17, 2026 at 8:49 pm

    Ok, I think I’ve found what’s going wrong. The fact is I have not started to code from scratch. I had an already working project, but I had to re-built data access in order to make the project work with several SGBDs. Thus, I used NHibernate. As I’m not the person who started the project, I have not a 100% knowledge of what has been done so far, so there was some piece of code that NHibernate didn’t like.
    For example, there was a case where a object with a given Id was loaded by the NHibernate session, and somewhere else in the code, the object was re-created and then updated :

    MyObject a = session.createQuery("from MyObject m where m.Id = 0");
    

    And somewhere else in the code:

    MyObject a = new MyObject();
    a.Id = 0;
    session.Update(a);
    

    This is making NHibernate sick because the same session holds two entities of the same type with the same Id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some context: I have an MVC3 .net project which, for the sake of
Let me describe a simple use-case: Running all tests in our project may take
Let me first describe my goal: I have created an object with 3 properties:
Let me describe my problem first. I have a class which holds a NSMutableDictionary
Let me first describe the problem. I have this application that opens a word
Let me describe the behavior I get: Load a user from the database: this
I've got a strange problem. Let me first describe my situation: Webserver01 (Webapplication, SQL,
Let's say I have the following two pieces of XML in my database <!--
Let me describe what i want to do: There is a Match model, which
I apologize that the title may not make sense, so let me describe my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.