title: Why do I get org.hibernate.HibernateException: No CurrentSessionContext configured
body: <p>I'm writing a simple project, a business app written in Swing, using Hibernate for back-end. I come from Spring, that gave me easy ways to use hibernate and transactions. Anyway I managed to have Hibernate working. Yesterday, while writing some code to delete a bean from DB, I got this: </p>
  
  <pre><code>org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
  </code></pre>
  
  <p>The deletion code is simply:</p>
  
  <pre><code>    Session sess = HibernateUtil.getSession();
      Transaction tx = sess.beginTransaction();
      try {
          tx.begin();
          sess.delete(ims);
      } catch (Exception e) {
          tx.rollback();
          throw e;
      }
      tx.commit();
      sess.flush();
  </code></pre>
  
  <p>and my <code>HibernateUtil.getSession()</code> is:</p>
  
  <pre><code>    public static Session getSession() throws HibernateException {
          Session sess = null;
          try {
              sess = sessionFactory.getCurrentSession();
          } catch (org.hibernate.HibernateException he) {
              sess = sessionFactory.openSession();
          }
          return sess;
      }
  </code></pre>
  
  <p>additional details: I never close a hibernate session in my code, just on application closing. Is this wrong? Why do I get this on delete (only for that bean, others do work), and I don't on other operations (Insert, query, update)?</p>
  
  <p>I read around and I tried to modify my <code>getSession</code> method simply in a <code>sessionFactory.getCurrentSessionCall()</code>, but I got: <code>org.hibernate.HibernateException: No CurrentSessionContext configured!</code></p>
  
  <p>Hibernat conf:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory &gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost/joptel&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;******&lt;/property&gt;
      &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
  
  
      ..mappings..
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>