bshaw wrote:
Well, a collection simply cannot be associated with 2 open sessions simultaneously. You just have to avoid this from happening. You may want to evict (session.evict) the relevant object (graph) from the first session before passing it to the second session. If need be, after the second session is closed, you could re-attach the object to session 1.
Hope this helps. Please remeber to rate the posting if this is helpful.
I figured it out too. :) My problem was caused by me starting a thread and sending in an instance from another session. I solved this by sending the ID to the new thread, opening it in a new session.
Code:
new Runnable() {
public void run() {
HibernateUtil.beginTransaction();
org.hibernate.Query q = HibernateUtil.getSession().createQuery("from CronJob job where job.id = :id");
q.setLong("id", jobPK);
((CronJob) q.list().get(0)).run();
HibernateUtil.closeSession();
}
}
Feels a bit quick and dirty, but this was an OK solution for me. I'm sure there are plenty of examples when you don't want to do this. You might have made changes to the instance without committing and need these changes in the new thread. (Perhaps Hibernate take care of that, I don't know.)