title: Getting org.hibernate.InvalidMappingException: Unable to read XML
body: <p>I am using NetbeansIDE 7.2. and pgAdmin III PostgreSQL 9.2 with Database name "StudentReports".</p>
  
  <p>I know a little of Hibernate and generating JasperReports using native SQL through JDBC Connection, but I am new to generating JasperReports connecting thru Hibernate Connection which this tutorial shows.</p>
  
  <p>I am getting o<code>rg.hibernate.InvalidMappingException: Unable to read XML Error</code> and <em>never</em> made a successful Hibernate Connection test, an error pops up saying "Could not parse mapping document from resource com/report/mappings/Department.hbm.xml", after following this tutorial <a href="http://bhaskaravignesh-j2ee.blogspot.com/2010/07/jasperreports-with-hibernate.html" rel="nofollow">"JasperReports with Hibernate - Module 1"</a> and <a href="http://bhaskaravignesh-j2ee.blogspot.com/2010/07/jasperreports-with-hibernate-module-2.html" rel="nofollow">JasperReports with Hibernate - Module 2</a>. It has 2 Modules. But I did a little modifications on its data access object (DAO) files and I just wanted to have a Department Records. Also, I used a different version of Hibernate and Jasper Reports Package and iReport Plugin for Netbeans which are Hibernate Release 4.1.9 and Jasper Reports 5.0.1 and iReport-4.5.0. I have added all of the jar files of it to my project's Library.</p>
  
  <p>This is my first time handling hibernate mapping xml files and data access object files.</p>
  
  <blockquote>
    <p>log4j:WARN No appenders could be found for logger (org.jboss.logging).
    log4j:WARN Please initialize the log4j system properly.<br>
    Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
        at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
        at org.hibernate.cfg.Configuration.add(Configuration.java:478)
        at org.hibernate.cfg.Configuration.add(Configuration.java:474)
        at org.hibernate.cfg.Configuration.add(Configuration.java:647)
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2115)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2087)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2067)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2020)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1935)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1914)
        at com.report.dao.DepartmentDAO.saveDepartment(DepartmentDAO.java:20)
        at com.report.test.AddDepartments.main(AddDepartments.java:20)
    Caused by: org.dom4j.DocumentException: Error on line 15 of document  : The element type "hibernate-mapping" must be terminated by the matching end-tag "". Nested exception: The element type "hibernate-mapping" must be terminated by the matching end-tag "".
        at org.dom4j.io.SAXReader.read(SAXReader.java:482)
        at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
        ... 12 more
    Java Result: 1</p>
  </blockquote>
  
  <p>These are my codes:</p>
  
  <p><strong>Department.java</strong></p>
  
  <pre><code>package com.report.beans;
    public class Department  implements java.io.Serializable {
  
   private int id;
   private String name;
  
  public long getId() {
      return this.id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  public String getName() {
      return this.name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  }
  </code></pre>
  
  <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://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; 
  &lt;hibernate-configuration&gt;
   &lt;session-factory&gt;
   &lt;property name="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
    &lt;property name="hibernate.connection.url"&gt; jdbc:postgresql://localhost:5432/StudentReports&lt;/property&gt;
    &lt;property name="hibernate.connection.username"&gt;postgres&lt;/property&gt;
    &lt;property name="hibernate.connection.password"&gt;postgres&lt;/property&gt;
    &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
    &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
    &lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
     &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;    
  
  &lt;mapping resource="com/report/mappings/Department.hbm.xml"/&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Department.hbm.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping&gt;
  &lt;class name="com.report.beans.Department"  lazy="false" table="Department" schema="dbo"      catalog="StudentReports"/&gt;
          &lt;id name="id" type="long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="increment" /&gt;
      &lt;/id&gt;
      &lt;property name="name" type="string"&gt;
          &lt;column name="name" length="100" not-null="true" unique="true" /&gt;
      &lt;/property&gt;
  </code></pre>
  
  <p><br>
  </p>
  
  <p><strong>DepartmentDAO.java</strong></p>
  
  <pre><code>package com.report.dao;
  
  import com.report.beans.Department;
  import org.hibernate.Session;
  
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  public class DepartmentDAO{
  
  
  public String saveDepartment(Department department)
  {
  
      SessionFactory sessionF = new Configuration().configure().buildSessionFactory();
      Session session = sessionF.openSession();
  
  //  This is the code I modified. I didn'y use HibernateSessionFactory
  //  Session session = HibernateSessionFactory.getSession();
      String Result = "";
  
      try
      {
          session.beginTransaction();
          session.save(department);
          session.getTransaction().commit();
          session.close();
          Result = "Department Saved Successfully";
      }
      catch(Exception e)
      {
          e.printStackTrace();
          session.close();
          Result = "Department was not saved due to the above Exception";
      }
  
      return Result;
  }
  }
  </code></pre>
  
  <p><strong>AddDepartments.java</strong></p>
  
  <pre><code>package com.report.test;
  
  import com.report.beans.Department;
  import com.report.dao.DepartmentDAO;
  
  public class AddDepartments
  {
  public static void main(String args[])
  {
      Department electronics = new Department();
          electronics.setName("Electronics Engineering");
  
      Department computerScience = new Department();
          computerScience.setName("Computer science Engineering");
  
      Department civil = new Department();
          civil.setName("Civil Engineering");
  
  
      String Result1 = new DepartmentDAO().saveDepartment(electronics);
          System.out.println(Result1);
  
      String Result2 = new DepartmentDAO().saveDepartment(computerScience);
          System.out.println(Result2);
  
      String Result3 = new DepartmentDAO().saveDepartment(civil);
          System.out.println(Result3);
  }
  }
  </code></pre>