This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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) ...
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);