-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Illegal attempt 2 associate a collection with 2 open session
PostPosted: Fri Sep 08, 2006 3:19 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:NHibernate v1.0.2

Mapping documents:

Development Environment: ASP.NET 2.0 (C#)


Name and version of the database you are using: SQL SERVER EXPRESS 2005

Dear members.

I'm having an exception while trying to save a MANY - TO - MANY relationship .. The classes are : Category and Item ...
I'm using IList with <bag> .

In the category facade class, i've implemented the SaveCollectionItem () method:

ArrayList itemlist = new ArrayList();
itemlist.Add(item);
cat.idcategoryiditems = itemlist;

mgr.saveItem(item);
Save(cat);

The saveItem is successfully saved but the Category saving is fainling and raising the following exception (the Category class is successfully saved apart but here tthe exception is raised) :

Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
Parameter name: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
Actual value was System.ArgumentOutOfRangeException: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 335
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 310
at nhExhibition.BusinessFacade.CategoryFacade.Save(Category cat) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 32
at nhExhibition.BusinessFacade.CategoryFacade.SaveCatItemsCollections(Category cat, Item item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 86.
Parameter name: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
Parameter name: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
Actual value was System.ArgumentOutOfRangeException: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 335
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 310
at nhExhibition.BusinessFacade.CategoryFacade.Save(Category cat) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 32
at nhExhibition.BusinessFacade.CategoryFacade.SaveCatItemsCollections(Category cat, Item item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 86.
Actual value was System.ArgumentOutOfRangeException: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
Parameter name: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
Actual value was System.ArgumentOutOfRangeException: Illegal attempt to associate a collection with two open sessions
Parameter name: Illegal attempt to associate a collection with two open sessions
Actual value was NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at NHibernate.Collection.PersistentCollection.SetCurrentSession(ISessionImplementor session)
at NHibernate.Impl.OnUpdateVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 326.
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item, Boolean pointlessParameter) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 335
at nhExhibition.DataAccess.ExhibitionDBMgr.Save(Object item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.DataAccess\ExhibitionDBMgr.cs:line 310
at nhExhibition.BusinessFacade.CategoryFacade.Save(Category cat) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 32
at nhExhibition.BusinessFacade.CategoryFacade.SaveCatItemsCollections(Category cat, Item item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 86.
at nhExhibition.BusinessFacade.CategoryFacade.SaveCatItemsCollections(Category cat, Item item) in C:\Documents and Settings\bacem\My Documents\Visual Studio 2005\Projects\Exhibition 03\nhExhibition.BusinessFacade\CategoryFacade.cs:line 93
at AddItems.DoSave() in c:\Exhibition 03\AddItems.aspx.cs:line 128
at AddItems.button_save_Click(Object sender, EventArgs e) in c:\Exhibition 03\AddItems.aspx.cs:line 136.



Regards,
Jojorico

_________________
In Code We Trust


Top
 Profile  
 
 Post subject: Re: Illegal attempt 2 associate a collection with 2 open ses
PostPosted: Sun Sep 10, 2006 3:32 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Hi,

Maybe you should show us your mappings. It looks like your Category class is not in the session that saves the item, but the latter tries to update it into its context (?). Or do you add an item to a Category that was addded (and saved) to another Category before?


Top
 Profile  
 
 Post subject: Re cascade="all-delete-orphan"
PostPosted: Mon Sep 11, 2006 9:32 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear GR,

Thanks for the reply, but i've solved the problem, i removed the cascade="all-delete-orphan" attribute ... but i think that this will affecte saving and deleting (into database) the collections and classes that are members in other classes ...
is that right ? so if i have 2 classes having a many-to-many relationship for example:

1- Category (contains IList items as a member variable)
2- Item (contains Ilist Categories as a member variable)


How can i save the category's collection ?
How can i delete the category's collection ?

In the case of a One-To-Many Relationship, how save and delete can be done ?

1- Category (contains IList items as a member variable)
2- Item (contains Category cat as a member variable)


Does the route differ between 1-to-n and n-to-1 ?

10x in advance

p.s: I had problems with declaring the DA class constructor as static, but removeing the cascade attribute have fixed that.

Regards,
Jojorico

_________________
In Code We Trust


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.