title: Very low performance with Glassfish 3.1.2 and Java EE + Hibernate
body: <p>I faced with very very low performance of Java EE (EJB + JSF) application and Hibernate(3.6.8.Final and 4.1.7.Final) on Glassfish 3.1.2. Sending about 300 select queries takes about 20 seconds. This is unacceptable.</p>
  
  <p>I have exactly the same application deployed on JBoss and TomEE. There, the same 300 select queries takes about 1,5 second.</p>
  
  <p>I found in google some answers that maybe <code>hibernate.show_sql</code> is <code>true</code> or <code>hibernate.hbm2ddl</code> make application soo slow. But it is not true. I turned off <code>hibernate.show_sql</code> but is doesn't matter. Moreover, these options are true in the JBoss and TomEE versions and it works over 10 times faster!
  I thought that this is the issue between Glasfish and Hibernate. But I have the next application with the same business logic, the same DAO with EntityManager provided by Hibernate but configurated with Spring. And the performance is great. It is weird, isn't it?</p>
  
  <p><code>persistence.xml</code> from the defect version:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt;
  
     &lt;persistence-unit name="jee_project" transaction-type="JTA"&gt;
        &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
        &lt;jta-data-source&gt;jdbc/PostgreSQL&lt;/jta-data-source&gt;
        &lt;properties&gt;
           &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
           &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
           &lt;property name="hibernate.show_sql" value="false"/&gt;
           &lt;property name="current_session_context_class" value="thread"/&gt;
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Glassfish JDBC configuration</p>
  
  <pre><code>&lt;jdbc-connection-pool driver-classname="" datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource" res-type="javax.sql.ConnectionPoolDataSource" description="" name="PostgreSQLPool"&gt;
        &lt;property name="User" value="postgresql"&gt;&lt;/property&gt;
        &lt;property name="DatabaseName" value="qazxsw"&gt;&lt;/property&gt;
        &lt;property name="LogLevel" value="0"&gt;&lt;/property&gt;
        &lt;property name="Password" value="1234"&gt;&lt;/property&gt;
        &lt;property name="ServerName" value="localhost"&gt;&lt;/property&gt;
        &lt;property name="Ssl" value="false"&gt;&lt;/property&gt;
        &lt;property name="ProtocolVersion" value="0"&gt;&lt;/property&gt;
        &lt;property name="TcpKeepAlive" value="false"&gt;&lt;/property&gt;
        &lt;property name="SocketTimeout" value="0"&gt;&lt;/property&gt;
        &lt;property name="PortNumber" value="5432"&gt;&lt;/property&gt;
        &lt;property name="LoginTimeout" value="0"&gt;&lt;/property&gt;
        &lt;property name="UnknownLength" value="2147483647"&gt;&lt;/property&gt;
        &lt;property name="PrepareThreshold" value="5"&gt;&lt;/property&gt;
      &lt;/jdbc-connection-pool&gt;
      &lt;jdbc-resource pool-name="PostgreSQLPool" description="" jndi-name="jdbc/PostgreSQL__pm"&gt;&lt;/jdbc-resource&gt;
      &lt;jdbc-resource pool-name="PostgreSQLPool" description="" jndi-name="jdbc/PostgreSQL__nontx"&gt;&lt;/jdbc-resource&gt;
  </code></pre>