title: application.properties vs hibernate.cfg.xml in spring boot application
body: <p>I've configured hibernate properties in <code>application.properties</code> file of my spring boot application. </p>
  
  <p><strong>application.properties</strong></p>
  
  <pre><code>#hibernate config
  spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
  spring.datasource.url=&lt;db_url&gt;
  spring.datasource.username=&lt;username&gt;
  spring.datasource.password=&lt;password&gt;
  spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  # Show or not log for each sql query
  spring.jpa.show-sql = true
  # Naming strategy
  spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy     
  
  # ThymeLeaf
  spring.thymeleaf.cache= false
  spring.thymeleaf.mode=LEGACYHTML5   
  </code></pre>
  
  <p>I am getting error when I am trying to get session as </p>
  
  <pre><code>Configuration configuration = new Configuration();
  configuration.configure("application.properties");
  StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
  SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
  Session session = sessionFactory.openSession();
  </code></pre>
  
  <p><strong>ERROR:</strong></p>
  
  <pre><code>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: 
  Could not parse configuration: application.properties] with root cause
  
  org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
  </code></pre>
  
  <p>I think its expecting <code>hibernate.cfg.xml</code> file in the class path as well? </p>
  
  <p>Is there any way I can only use <code>application.properties</code> or I have to move all hibernate related properties to <code>hibernate.cfg.xml</code> or <code>hibernate.properties</code> file?</p>
  
  <p><strong>getSelectedStudents</strong></p>
  
  <pre><code>public List getSelectedStudents(){
      final EntityManagerFactory emf = null;
      EntityManager em = emf.createEntityManager();
  
      Query q = em.createNativeQuery("SELECT s.student_id, s.first_name, s.last_name, s.city FROM Student s "
                                      + "where s.city=:city and s.last_name = :lname", Student.class);
      q.setParameter("city", "London");
      q.setParameter("lname", "Rizwan");
  
      List&lt;Student&gt; students = q.getResultList();
  
      for (Student s : students) {
          System.out.println("Student "
                  + s.getFirstName()
                  + " "
                  + s.getLastName());
      }
  
      return students;
  }   
  </code></pre>
  
  <p><strong>Error 2:</strong></p>
  
  <pre><code>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  
  java.lang.NullPointerException: null
      at com.school.service.StudentServiceImplementation.getSelectedStudents(StudentServiceImplementation.java:69) ~[classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_77]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_77] 
  </code></pre>
  
  <p>EDIT:
  as suggested to use Entity Manager, I've added getSelectedStudents method. I am still getting error at <code>EntityManager em = emf.createEntityManager();</code> 
  see Error 2 for details.</p>