title: Hibernate + MySQL Process remaining in "sleep" state
body: <p>I know there has been a lot of questions on this topic, but I found no answer that suits my needs. 
  I have a very simple requirement: open a connection to a MySQL database, make a query, get the result and close the connection.</p>
  
  <p>Here is my code: </p>
  
  <p><strong>Hibernate file:</strong> </p>
  
  <pre><code>&lt;?xml version='1.0' encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://192.168.254.90:3306/db&lt;/property&gt;
          &lt;property name="connection.username"&gt;user&lt;/property&gt;
          &lt;property name="connection.password"&gt;password&lt;/property&gt;
          &lt;property name="connection.pool_size"&gt;0&lt;/property&gt;
          &lt;property name="show_sql"&gt;false&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>Java class:</strong> </p>
  
  <pre><code>final URL resourceUrl = getClass().getClassLoader().getResource("blabla.xml");
  final Configuration configuration = new Configuration().configure(new File(resourceUrl.toURI()));
  final SessionFactory sessionFactory = configuration.buildSessionFactory();
  final Session session = sessionFactory.openSession();
  session.setFlushMode(FlushMode.ALWAYS);
  final String sqlQueryStr = "SELECT col1 FROM table1 WHERE col2 = 'blabla'";
  final Query sqlQuery = session.createSQLQuery(sqlQueryStr);
  session.beginTransaction();
  final Map&lt;String, Object&gt; result = (Map&lt;String, Object&gt;) sqlQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE).uniqueResult()
  final String resultStr = result.get("col1").toString();
  session.getTransaction().commit();
  session.close();
  </code></pre>
  
  <p>This code leaves me with 1 process in MySQL that remains in "sleep" state, why? Moreover, if I want to reuse this session, it does not work because I did close it. So why does it let a "sleep" process, and in the same time cannot use it?</p>
  
  <p>Thanks!</p>