title: Hibernate 5 Native query support - Slow response generation
body: <p>I am trying to fetch 1000 rows using the Hibernate createNativeQuery. The query contains two joins. When I execute the same in SQL developer I see that response comes up in less than 400 ms but from the code it takes 20 sec to get the result. </p>
  
  <blockquote>
    <p>Table </p>
    
    <p>Employee - id, name, country_id, dept_id</p>
    
    <p>Country - id, country_name, office_count,inflation_rate</p>
    
    <p>Dept - id, dept_name,manager</p>
  </blockquote>
  
  <pre><code>String queryStr = "Select e.id as id, e.name as empName, c.country_name AS countryName,
      d.dept_name AS deptName FROM  owner.Employee AS e LEFT OUTER JOIN owner.Country c
          ON e.country_id = c.id LEFT OUTER JOIN owner.Dept AS d ON e.country_id = d.id";
  
  List&lt;Object[]&gt; rows  = this.getSession().createNativeQuery(queryStr).setMaxResults(1000)
      .addScalar( "id", StringType.INSTANCE )
      .addScalar( "empName", StringType.INSTANCE )
      .addScalar( "countryName", StringType.INSTANCE )
      .addScalar( "deptName", StringType.INSTANCE )
      .list();
  </code></pre>
  
  <p>What is the additional processing that Hibernate is doing that could be causing this delay ? Is there someway I could optimize the code ?</p>