title: Failed to create sessionFactory object.org.hibernate.HibernateException
body: <p>Hi I am new to the hibernate framework.when i am running hibernate sample example code it is working fine if internet connection is available.If internet connection is not available then it is not working and is giving error like below:</p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
  log4j:WARN Please initialize the log4j system properly.
  Failed to create sessionFactory object.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at com.hb.example.ManageEmployee.main(ManageEmployee.java:20)
  Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
      at com.hb.example.ManageEmployee.main(ManageEmployee.java:17)
  Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
      at org.dom4j.io.SAXReader.read(SAXReader.java:484)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
      ... 3 more
  </code></pre>
  
  <p>My example code will be like below:
  Employee.java:</p>
  
  <pre><code>package com.hb.example;
  
  public class Employee {
         private int id;
         private String firstName; 
         private String lastName;   
         private int salary;  
  
         public Employee() {}
         public Employee(String fname, String lname, int salary) {
            this.firstName = fname;
            this.lastName = lname;
            this.salary = salary;
         }
         public int getId() {
            return id;
         }
         public void setId( int id ) {
            this.id = id;
         }
         public String getFirstName() {
            return firstName;
         }
         public void setFirstName( String first_name ) {
            this.firstName = first_name;
         }
         public String getLastName() {
            return lastName;
         }
         public void setLastName( String last_name ) {
            this.lastName = last_name;
         }
         public int getSalary() {
            return salary;
         }
         public void setSalary( int salary ) {
            this.salary = salary;
         }
      }
  </code></pre>
  
  <p>ManageEmployee.java:</p>
  
  <pre><code>package com.hb.example;
  
  import java.util.List; 
  import java.util.Date;
  import java.util.Iterator; 
  
  import org.hibernate.HibernateException; 
  import org.hibernate.Session; 
  import org.hibernate.Transaction;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  public class ManageEmployee {
     private static SessionFactory factory; 
     public static void main(String[] args) {
        try{
           factory = new Configuration().configure().buildSessionFactory();
        }catch (Throwable ex) { 
           System.err.println("Failed to create sessionFactory object." + ex);
           throw new ExceptionInInitializerError(ex); 
        }
        ManageEmployee ME = new ManageEmployee();
  
        /* Add few employee records in database */
        Integer empID1 = ME.addEmployee("Zara", "Ali", 1000);
        Integer empID2 = ME.addEmployee("Daisy", "Das", 5000);
        Integer empID3 = ME.addEmployee("John", "Paul", 10000);
  
        /* List down all the employees */
        ME.listEmployees();
  
        /* Update employee's records */
        ME.updateEmployee(empID1, 5000);
  
        /* Delete an employee from the database */
        ME.deleteEmployee(empID2);
  
        /* List down new list of the employees */
        ME.listEmployees();
     }
     /* Method to CREATE an employee in the database */
     public Integer addEmployee(String fname, String lname, int salary){
        Session session = factory.openSession();
        Transaction tx = null;
        Integer employeeID = null;
        try{
           tx = session.beginTransaction();
           Employee employee = new Employee(fname, lname, salary);
           employeeID = (Integer) session.save(employee); 
           tx.commit();
        }catch (HibernateException e) {
           if (tx!=null) tx.rollback();
           e.printStackTrace(); 
        }finally {
           session.close(); 
        }
        return employeeID;
     }
     /* Method to  READ all the employees */
     public void listEmployees( ){
        Session session = factory.openSession();
        Transaction tx = null;
        try{
           tx = session.beginTransaction();
           List employees = session.createQuery("FROM Employee").list(); 
           for (Iterator iterator = 
                             employees.iterator(); iterator.hasNext();){
              Employee employee = (Employee) iterator.next(); 
              System.out.print("First Name: " + employee.getFirstName()); 
              System.out.print("  Last Name: " + employee.getLastName()); 
              System.out.println("  Salary: " + employee.getSalary()); 
           }
           tx.commit();
        }catch (HibernateException e) {
           if (tx!=null) tx.rollback();
           e.printStackTrace(); 
        }finally {
           session.close(); 
        }
     }
     /* Method to UPDATE salary for an employee */
     public void updateEmployee(Integer EmployeeID, int salary ){
        Session session = factory.openSession();
        Transaction tx = null;
        try{
           tx = session.beginTransaction();
           Employee employee = 
                      (Employee)session.get(Employee.class, EmployeeID); 
           employee.setSalary( salary );
           session.update(employee); 
           tx.commit();
        }catch (HibernateException e) {
           if (tx!=null) tx.rollback();
           e.printStackTrace(); 
        }finally {
           session.close(); 
        }
     }
     /* Method to DELETE an employee from the records */
     public void deleteEmployee(Integer EmployeeID){
        Session session = factory.openSession();
        Transaction tx = null;
        try{
           tx = session.beginTransaction();
           Employee employee = 
                     (Employee)session.get(Employee.class, EmployeeID); 
           session.delete(employee); 
           tx.commit();
        }catch (HibernateException e) {
           if (tx!=null) tx.rollback();
           e.printStackTrace(); 
        }finally {
           session.close(); 
        }
     }
  }
  </code></pre>
  
  <p>hibernate.cfg.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  </code></pre>
  
  <p>&lt;-----></p>
  
  <p>&lt;--  ---></p>
  
  <pre><code>&lt;hibernate-configuration&gt;
     &lt;session-factory&gt;
     &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
     &lt;property name="hibernate.dialect"&gt;
        org.hibernate.dialect.MySQLDialect
     &lt;/property&gt;
     &lt;property name="hibernate.connection.driver_class"&gt;
        com.mysql.jdbc.Driver
     &lt;/property&gt;
  
     &lt;!-- Assume test is the database name --&gt;
     &lt;property name="hibernate.connection.url"&gt;
        jdbc:mysql://localhost/test
     &lt;/property&gt;
     &lt;property name="hibernate.connection.username"&gt;
        root
     &lt;/property&gt;
     &lt;property name="hibernate.connection.password"&gt;
        root
     &lt;/property&gt;
  
     &lt;!-- List of XML mapping files --&gt;
     &lt;mapping resource="Employee.hbm.xml"/&gt;
  
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Employee.hbm.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  </code></pre>
  
  <p>Here i done the modification but it is not working</p>
  
  <p>&lt;--- 
       ---></p>
  
  <pre><code>&lt;hibernate-mapping&gt;
     &lt;class name="com.hb.example.Employee" table="EMPLOYEE"&gt;
        &lt;meta attribute="class-description"&gt;
           This class contains the employee detail. 
        &lt;/meta&gt;
        &lt;id name="id" type="int" column="id"&gt;
           &lt;generator class="native"/&gt;
        &lt;/id&gt;
        &lt;property name="firstName" column="first_name" type="string"/&gt;
        &lt;property name="lastName" column="last_name" type="string"/&gt;
        &lt;property name="salary" column="salary" type="int"/&gt;
     &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>So can any one help please for me.</p>