It def. has something to do with your session management.  Some where,
your collection is being accessed by two or more open sessions.  Your
trying to update the collection in one session but the collection also
lives in another, hence the problem when trying to perform an update.

Run through the pages life cycle and see if your not opening more than
one session.  I highly recommend using Spring.NET's OSIV module and
Declarative Transaction Management as it frees you from session and
transaction management and offers a really clean approach.  I'd be
more than happy to point you in the right direction if you would like.



On Dec 2, 6:41 am, senzacionale <[email protected]> wrote:
> Hi,
>
> When i am inserting into DB everything works, but when i update i get
> error of "Illegal attempt to associate a collection with two open
> sessions". I use transaction, but if i do not have for example
> userDao.CommitChanges(); nothing is stored to DB, but if i use
> userDao.CommitChanges(); then i get previous error. I search in forum,
> google try many things but no one works. Problem is that in VS 2008
> update works, in IIS i get this problem.
>
> Looks like session lifetime management problem and not with mapping.
>
> When i debug in IIS i get this
>
> problem is in this code
>
> Code:
> public void CommitChanges() {
>             if (NHibernateSessionManager.Instance.HasOpenTransactionOn
> (SessionFactoryConfigPath)) {
>                 NHibernateSessionManager.Instance.CommitTransactionOn
> (SessionFactoryConfigPath);
>             }
>             else {
>                 // If there's no transaction, just flush the changes
>                 NHibernateSessionManager.Instance.GetSessionFrom
> (SessionFactoryConfigPath).Flush();
>             }
>         }
>
> public void CommitTransactionOn(string sessionFactoryConfigPath) {
>             ITransaction transaction = (ITransaction)
> ContextTransactions[sessionFactoryConfigPath];
>
>             try {
>                 if (HasOpenTransactionOn(sessionFactoryConfigPath)) {
>                     transaction.Commit();
>                     ContextTransactions.Remove
> (sessionFactoryConfigPath);
>                 }
>             }
>             catch (HibernateException) {
>                 RollbackTransactionOn(sessionFactoryConfigPath);
>                 throw;
>             }
>         }
>
>         public bool HasOpenTransactionOn(string
> sessionFactoryConfigPath) {
>             ITransaction transaction = (ITransaction)
> ContextTransactions[sessionFactoryConfigPath];
>
>             return transaction != null && !transaction.WasCommitted
> && !transaction.WasRolledBack;
>         }
>
> always is calling else statement in CommitChanges() method. When i
> update never gone to commitchanges().
>
> Fluent NHibernate version:
> 1:0 RTM
>
> Code for update
>
> Code:
> user.Name = txtName.Text;
> user.Surname = txtSurname.Text;
> user.HealthCardId = txtHealthCardId.Text;
> user.Address = address;
> userDao.Update(user);
> userDao.CommitChanges();
>
> Code:
> public T Update(T entity)
>         {
>             NHibernateSession.Update(entity);
>             return entity;
>         }
>
> Name and version of the database you are using:
> MSSQL 2008
>
> Full stack trace of any exception that occurs:
>
> Quote:
> Server Error in '/' Application.
> Illegal attempt to associate a collection with two open sessions
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: NHibernate.HibernateException: Illegal attempt to
> associate a collection with two open sessions
>
> Source Error:
>
> An unhandled exception was generated during the execution of the
> current web request. Information regarding the origin and location of
> the exception can be identified using the exception stack trace below.
>
> Stack Trace:
>
> [HibernateException: Illegal attempt to associate a collection with
> two open sessions]
> NHibernate.Collection.AbstractPersistentCollection.SetCurrentSession
> (ISessionImplementor session) +237
>
> NHibernate.Event.Default.OnUpdateVisitor.ProcessCollection(Object
> collection, CollectionType type) +184
> NHibernate.Event.Default.AbstractVisitor.ProcessValue(Int32 i, Object
> [] values, IType[] types) +46
> NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues
> (Object[] values, IType[] types) +74
>
> NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformUpdate
> (SaveOrUpdateEvent event, Object entity, IEntityPersister persister)
> +432
> NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate
> (SaveOrUpdateEvent event) +99
>
> NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate
> (SaveOrUpdateEvent event) +333
> NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
> +162
> NHibernate.Impl.SessionImpl.SaveOrUpdate(String entityName, Object
> obj) +151
>
> NHibernate.Engine.SaveUpdateCascadingAction.Cascade(IEventSource
> session, Object child, String entityName, Object anything, Boolean
> isCascadeDeleteEnabled) +139
> NHibernate.Engine.Cascade.CascadeOn(IEntityPersister persister, Object
> parent, Object anything) +578
>
> NHibernate.Event.Default.AbstractFlushingEventListener.CascadeOnFlush
> (IEventSource session, IEntityPersister persister, Object key, Object
> anything) +145
> NHibernate.Event.Default.AbstractFlushingEventListener.PrepareEntityFlushes
> (IEventSource session) +387
>
> NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions
> (FlushEvent event) +292
> NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
> event) +85
> NHibernate.Impl.SessionImpl.Flush() +275
>
> ProjectBase.Data.AbstractNHibernateDao`2.CommitChanges() in D:
> \PROJEKTI
> \eMedicine\ProjectBase.Data\AbstractNHibernateDao.cs:120
> EMedicine.UserControls.UsersUC.btnAdd_Update(Object sender, EventArgs
> e) in D:\PROJEKTI\eMedicine\eMedicine\UserControls\UsersUC.ascx.cs:390
>
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
> System.Web.UI.WebControls.Button.RaisePostBackEvent(String
> eventArgument) +140
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +29
>
> System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> +2981
>
> Any idea what can be wrong?

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to