Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Miro Ricco
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic