learn java
The moose likes Object Relational Mapping and the fly likes After delete I get: Illegal attempt to associate a collection with two open sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "After delete I get: Illegal attempt to associate a collection with two open sessions" Watch "After delete I get: Illegal attempt to associate a collection with two open sessions" New topic
Author

After delete I get: Illegal attempt to associate a collection with two open sessions

Miro Ricco
Ranch Hand

Joined: Apr 16, 2002
Posts: 40
Hi

I have two classes Person and Team bound in many-to-one relation via foreign key.
When I try to delete Person or a Team I get:

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:761)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:739)
at sk.dopris.dao.PersonDAO.delete(PersonDAO.java:65)
...

Do you happen to know what could be the problem?

Kind regards
Miro
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Well, based on the exception it looks like you have two sessions running at the same time, and you have one session that is managing the object, then you pass the object to the delete method of the other session object. like

Session s = sf.openSession();
MyObject a = s.load(someobject, someid);
Session s2 = sf.openSession();
s2.delete(a);


You can't do something like that.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: After delete I get: Illegal attempt to associate a collection with two open sessions