title: Hibernate: Could not parse configuration: hibernate.cfg.xml?
body: <p>I am getting the following error when trying to use <code>Hibernate</code> withing my application:</p>
  
  <pre><code>org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
  </code></pre>
  
  <p>What is causing this? Please see <code>hibernate.cfg.xml</code> , <code>output</code> and <code>Runner class</code> below?</p>
  
  <p>Note: I have looked at <a href="https://stackoverflow.com/questions/19889132/error-the-processing-instruction-target-matching-xxmmll-is-not-allowed">this answer</a> and tried to fix it using suggestions, but with no luck.</p>
  
  <p><strong>hibernate.cfg.xml:</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;!-- Database connection settings --&gt;
              &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
              &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/test-db&lt;/property&gt;
              &lt;property name="connection.username"&gt;user&lt;/property&gt;
              &lt;property name="connection.password"&gt;password&lt;/property&gt;
  
              &lt;!-- SQL dialect --&gt;
              &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
              &lt;!-- Echo all executed SQL to stdout --&gt;
              &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
              &lt;!-- Use XML-based mapping metadata --&gt; 
              &lt;!-- &lt;mapping resource="domain/Message.hbm.xml"/&gt; --&gt;
  
              &lt;!-- Use Annotation-based mapping metadata --&gt;
              &lt;mapping class="entity.Message"/&gt;            
  
          &lt;/session-factory&gt;
      &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Successfully started process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe''
  Dec 16, 2015 12:01:20 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
  Dec 16, 2015 12:01:20 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.3.5.Final}
  Dec 16, 2015 12:01:21 AM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Dec 16, 2015 12:01:21 AM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Dec 16, 2015 12:01:21 AM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
  Dec 16, 2015 12:01:21 AM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: hibernate.cfg.xml
  Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at util.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
      at util.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:12)
      at client.HelloWorldClient.main(HelloWorldClient.java:13)
  Caused by: org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2163)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
      at util.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
      ... 2 more
  Caused by: org.dom4j.DocumentException: Error on line 2 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
      at org.dom4j.io.SAXReader.read(SAXReader.java:482)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155)
      ... 4 more
  :run FAILED
  :run (Thread[Daemon worker Thread 15,5,main]) completed. Took 0.617 secs.
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':run'.
  &gt; Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 1
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
  
  BUILD FAILED
  </code></pre>
  
  <p><strong>Runner Class:</strong></p>
  
  <pre><code>package client;
  
  import org.hibernate.Session;
  
  import util.HibernateUtil;
  import entity.Message;
  
  
  public class HelloWorldClient {
      public static void main(String[] args) {
  
                  Session session = HibernateUtil.getSessionFactory().openSession();
                  session.beginTransaction();
  
                  Message message = new Message( "Hello World with Hibernate &amp; JPA Annotations" ); 
  
                  session.save(message);
  
                  session.getTransaction().commit();
                  session.close();
  
      }
  }
  </code></pre>
  
  <p><strong>Edit: Error seen when hovering over session-factory tag :</strong></p>
  
  <p><a href="https://i.stack.imgur.com/45MtD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/45MtD.png" alt="enter image description here"></a></p>