N/APosted on - 08/09/2011
I am having issues with NHibernate. I have got a few methods in DAL and I use Session Factory.
When I run this application it runs perfectly alright, but there are sometimes it throws in an exception saying Entity <Entity Name> is already associated with entity ID <Number>.
I am looking for ways to solve this issue; any idea?
How to Solve NHibernate entity association issue?
NHibernates have different sessions of which session factory is one of them.
These errors usually occur when you are creating a new entity on every database call and sometimes using old ones.
If you are using Poco entities, the frequency of this issue will be reduced to 10% and get the session object for poco entity in each method.
To resolve the method completely I am suggesting a method that worked for me: I cleared the session on every database call and in this way, everything worked for me.
Although am not sure if it will work for you, you can give it a trial.