Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate import: Employee -> Employee org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml
    primarykey
    data
    text
    <p>I am new t hibernate When I am trying to execute below code I am getting below Exception:</p> <p>org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml </p> <p>Here is my code:</p> <p>Configuration: </p> <pre><code> &lt;hibernate-configuration&gt; &lt;session-factory&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;property name="hibernate.connection.url"&gt; jdbc:mysql://localhost/hibernatetest &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>Source: </p> <pre><code> package com.practice.HBtest; public class Employee { private int id; private String firstName; private String lastName; private Integer 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>Mapping: </p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="Employee" table="EMPLOYEE"&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>Source extract:</p> <pre><code>import org.hibernate.HibernateException; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; public class EmployeeRecordManager { private static SessionFactory sessionFactory; private static ServiceRegistry serviceRegistry; private Session session; public static void main(String[] args) { EmployeeRecordManager erm = new EmployeeRecordManager(); try { Configuration cfg = new Configuration().addResource("Employee.hbm.xml"); SessionFactory sessionFactory = cfg.configure().buildSessionFactory(serviceRegistry); } catch (Exception e) { System.out.println(e); } Integer empID1 = erm.addEmployee("Amruta", "Ali", 1000); Integer empID2 = erm.addEmployee("Ruchi", "Das", 5000); Integer empID3 = erm.addEmployee("Mitul", "Paul", 10000); System.out.println(erm); } public Integer addEmployee(String fname, String lname, int salary) { Session session = sessionFactory.openSession(); Transaction tx = null; Integer empID = null; try { tx = session.beginTransaction(); Employee employee = new Employee(fname, lname, salary); empID = (Integer) session.save(employee); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } return empID; } } Nov 7, 2012 5:36:15 PM org.hibernate.annotations.common.Version &lt;clinit&gt; INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} Nov 7, 2012 5:36:15 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.1.8.Final} Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Environment &lt;clinit&gt; INFO: HHH000206: hibernate.properties not found Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: Employee.hbm.xml Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: /hibernate.cfg.xml Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: Employee.hbm.xml Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null Nov 7, 2012 5:36:15 PM org.hibernate.cfg.Configuration$MappingsImpl addImport INFO: HHH000071: Duplicate import: Employee -&gt; Employee org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3417) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3406) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3394) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) at com.practice.HBtest.EmployeeRecordManager.main(EmployeeRecordManager.java:24) Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Employee at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2582) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:174) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3414) ... 5 more Exception in thread "main" java.lang.NullPointerException at com.practice.HBtest.EmployeeRecordManager.addEmployee(EmployeeRecordManager.java:39) at com.practice.HBtest.EmployeeRecordManager.main(EmployeeRecordManager.java:30) org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml After Adding the code mentioned by you was getting below Exception: Nov 7, 2012 6:48:24 PM org.hibernate.annotations.common.Version &lt;clinit&gt; INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} Nov 7, 2012 6:48:24 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.1.8.Final} Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Environment &lt;clinit&gt; INFO: HHH000206: hibernate.properties not found Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: hibernate.cfg.xml Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: hibernate.cfg.xml Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: Employee.hbm.xml Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: /hibernate.cfg.xml Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: Employee.hbm.xml Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null Nov 7, 2012 6:48:24 PM org.hibernate.cfg.Configuration$MappingsImpl addImport INFO: HHH000071: Duplicate import: Employee -&gt; Employee org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3417) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3406) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3394) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) at com.practice.HBtest.EmployeeRecordManager.main(EmployeeRecordManager.java:24) Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Employee at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2582) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:174) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3414) ... 5 more Exception in thread "main" java.lang.NullPointerException at com.practice.HBtest.EmployeeRecordManager.addEmployee(EmployeeRecordManager.java:39) at com.practice.HBtest.EmployeeRecordManager.main(EmployeeRecordManager.java:30) org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload