title: HibernateException: Illegal attempt to associate a collection with two open sessions on calling session.update()
body: <p>I have a table which is associated with many other tables either with one to one or one to many relationships. While updating these tables with <code>session.update(Parent_Table)</code>, I get the following exception.</p>
  
  <blockquote>
    <p>org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions</p>
  </blockquote>
  
  <p>Update Method:  </p>
  
  <pre><code>public static String update(ParentTable table)  throws Exception {      
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      try {
          session.beginTransaction();
          session.update(table);
          session.getTransaction().commit();
          return success;
      } catch (Exception e) {
          session.getTransaction().rollback();
          e.printStackTrace();
          return failure;
      }
  }
  </code></pre>
  
  <p>Here I am adding new child records and making them associated with parent table or modifying existing parent or child record and passing the parent table to <code>session.update(table)</code>. </p>
  
  <p>No clue how two different sessions are getting created. Even though I close existing sessions before update statement and open a new session, getting the same exception.</p>
  
  <p>Could anybody suggest what might be going wrong here?</p>