a) this should go to the users list.
b) you are probably putting your user instance in the ASP.Net session,
which is not allowed unless you are also keeping NH session there.

On Thu, Dec 3, 2009 at 1:00 PM, senzacionale <[email protected]> wrote:
> 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.
>
> 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
>
> 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(). Any idea what can be wrong?
>

Reply via email to