title: Hibernate + PostgreSQL - Connection with state "Idle in transaction"
body: <p>I have a JSF application running on Tomcat using Hibernate.
  I have made a little test that exposed te problem - A servlet was created, and the only thing it does is this:</p>
  
  <pre><code>EntityManager em=null;
  try {
      em = ConnectDb.getEntityManager();
      em.createQuery("from Frete").getResultList();
  } catch (Exception e) {
      e.printStackTrace();
  } finally {
      try{em.close();}catch(Exception ex){}
  }
  </code></pre>
  
  <p>If i execute the following sql in pg_admin, i get one record, at the column "query" i see the sql executed by hibernate, and at the column "state" it says "idle in transaction".</p>
  
  <p>But the problem is that no transaction was started, the only thing i did was create a query. And the EntityManager was closed - there was no exception thrown when closing it.</p>
  
  <p>Maybe this is a configuration at persistence.xml, but i don't know. Here is my persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
    &lt;persistence-unit name="GestaoPU" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
        &lt;property name="hibernate.show_sql" value="true"/&gt;
        &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
        &lt;property name="hibernate.connection.autocommit" value="false"/&gt;
        &lt;property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/AtualyGestao"/&gt;
        &lt;property name="javax.persistence.jdbc.password" value="atg4747"/&gt;
        &lt;property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/&gt;
        &lt;property name="javax.persistence.jdbc.user" value="AtualyGestao"/&gt;
        &lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/&gt;
        &lt;property name="hibernate.format_sql" value="false"/&gt;
        &lt;property name="hibernate.connection.encoding" value="ISO-8859-1"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>