title: What is the use of Hibernate ? Its too Slow ? What is Missing for a developer?
body: <p>I am working on a web application project that require to interact with a database (Oracle 12c in this case):</p>
  
  <p>To understand and test the capabilities of Hibernate well( As I am a first time user of Hibernate): I wrote a small web application that calls a web service. That web service's backend in turn uses hibernate to fetch the data from Oracle Database,( It execute a read only query( a stored procedure via CreateSQLQuery)).</p>
  
  <p>It has given following results, ( where web service running on my local(tomcat 8), and database is in remote (aws)) :</p>
  
  <p>520 Records to Fetch : 21020 ms (Around 21 seconds to fetch ) </p>
  
  <p>3846 Records to Fetch : 172383 ms ( 172 Seconds ~ 3 Minutes )</p>
  
  <p>I have couple of questions :</p>
  
  <p><strong>1.</strong> I would like to know what is the use of Hibernate ? </p>
  
  <p><strong>2.</strong> Its too Slow in my first exercise, and I searched all over internet but didn't find any straight forward answer or directions ? </p>
  
  <p><strong>3.</strong> If you are the one who is using hibernate then may you please let me know why you are using this hibernate, and what business problem its solve ( e.g. is it for beginners who can just run basic web application ?)</p>
  
  <p><strong>4.</strong> May you please let me know what is missing for a developer from Hibernate?</p>
  
  <p>References :
  <a href="https://stackoverflow.com/questions/6609645/simple-hibernate-query-returning-very-slowly">simple-hibernate-query-returning-very-slowly</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12163268/why-is-the-hibernate-query-list-slow">why-is-the-hibernate-query-list-slow</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5155718/hibernate-performance">hibernate-performance</a></p>
  
  <p><a href="https://dba.stackexchange.com/questions/27698/hibernate-query-running-slow">hibernate-query-running-slow</a></p>
  
  <p><a href="https://stackoverflow.com/questions/20953436/sql-query-within-hibernate-extremely-slow-while-very-fast-using-sql-cient">sql-query-within-hibernate-extremely-slow-while-very-fast-using-sql-cient</a></p>
  
  <p>Below is the context with my simple Hibernate work :</p>
  
  <p><strong>Query :</strong> </p>
  
  <pre><code>List&lt;Model&gt; modelList = session.createSQLQuery("SELECT * FROM TABLE)
                  .addEntity(modelList.class).list();
  </code></pre>
  
  <p>*TABLE - I have changed the name for simplicity, overyall I am running only a simple select query to fetch the that, nothing complex,</p>
  
  <p><strong>Config 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="hibernate.connection.driver_class"&gt;oracle.jdbc.OracleDriver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:oracle:thin:@X.X.X.X:1521:orcl&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;*****&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;******&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;&lt;/property&gt;
          &lt;mapping class="x.x.x.x.xsModel" /&gt;
          &lt;mapping class="x.x.x.x.dModel" /&gt;
  
  
      &lt;/session-factory&gt; &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>HiberNate Util</strong> </p>
  
  <p>public class HibernateUtil
  {
      //private static final SessionFactory sessionFactory = buildSessionFactory();
      private static  SessionFactory sessionFactory = buildSessionFactory();</p>
  
  <pre><code>private static final Logger logger = LoggerFactory.getLogger(HibernateUtil.class);
  
  private static SessionFactory buildSessionFactory()
  {
      try
      {
          if (sessionFactory == null) {
              // loads configuration and mappings
              Configuration configuration = new Configuration().configure()
                      .setProperty("hibernate.connection.driver_class", "oracle.jdbc.OracleDriver")
                      .setProperty("hibernate.connection.url", "jdbc:oracle:thin:@X.X.X.X:orcl")
                      .setProperty("hibernate.connection.password","aaaaa")
                      .setProperty("hibernate.connection.username","aaaaa")
                      .setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect")
                      .setProperty("show_sql","true")
                      //.setProperty("hibernate.hbm2ddl.auto", "")
                     // .setProperty("hibernate.temp.use_jdbc_metadata_defaults","false")
                     // .setProperty("hibernate.jdbc.lob.non_contextual_creation","true")
              .addAnnotatedClass(dModel.class)
                      .addAnnotatedClass(sModel.class);
  
              ServiceRegistry serviceRegistry
                      = new StandardServiceRegistryBuilder()
                      .applySettings(configuration.getProperties()).build();
  
  
              // builds a session factory from the service registry
              sessionFactory = configuration.buildSessionFactory(serviceRegistry);
          }
          return sessionFactory;
      }
      catch (Throwable ex) {
          // Make sure you log the exception, as it might be swallowed
          logger.error("Initial SessionFactory creation failed." + ex);
          throw new ExceptionInInitializerError(ex);
      }
  }
  
  public static SessionFactory getSessionFactory() {
  
      return sessionFactory;
  }
  
  public static void shutdown() {
      // Close caches and connection pools
      getSessionFactory().close();
  }
  </code></pre>
  
  <p>}</p>