0

Hi Iam trying to run my hiberanate application i am getting the Hibernate Exception.

my hibernate.cfg.xml file is

<?xml version='1.0' encoding='UTF-8'?>

<session-factory>
    <property name="hbm2ddl.auto">update</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect </property>
    <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
    <property name="connection.username">root</property>
    <property name="connection.password">mysql</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

    <!--   <mapping resource="config\\hibernate.hbm.xml"/ -->
    <mapping resource="config\\employee.hbm.xml"/>>
</session-factory>

employee.hbm.xml

<?xml version='1.0' encoding='UTF-8'?>

<hibernate-mapping>

    <class name = "com.javatpoint.mypackage.Employee" table = "emp_TPCH" discriminator-value="emp">
        <id name = "id"> 
            <generator class = "increment">
            </generator>
        </id>
        <discriminator column="type" type= "string"></discriminator>
        <property name ="Name"></property>

        <subclass name = "com.javatpoint.mypackage.Regular_Employee" discriminator-value="reg_emp">
        <property name = "salary"></property>
        <property name = "bonus"></property>
        </subclass>

        <subclass name = "com.javatpoint.mypackage.Contract_Employee" discriminator-value = "con_emp">
        <property name = "pay_Per_Hour"></property>
        <property name = "contact_Duration"></property>
        </subclass>

    </class>
</hibernate-mapping>

Employee.java is

package com.javatpoint.mpackage;

public class Employee {

private int id;
private String name;
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getname() {
    return name;
}
public void setname(String name) {
    this.name = name;
}

}

Contract_Employee.java

package com.javatpoint.mpackage;

public class Contract_Employee extends Employee {

private float pay_Per_Hour;
private String contact_Duration;

public float getPay_Per_Hour() {
    return pay_Per_Hour;
}
public void setPay_Per_Hour(float pay_Per_Hour) {
    this.pay_Per_Hour = pay_Per_Hour;
}
public String getContact_Duration() {
    return contact_Duration;
}
public void setContact_Duration(String contact_Duration) {
    this.contact_Duration = contact_Duration;
}

}

Regular Employee.js is

package com.javatpoint.mpackage;

public class Regular_Employee extends Employee {

private float salary;
private int bonus;

public float getSalary() {
    return salary;
}
public void setSalary(float salary) {
    this.salary = salary;
}
public int getBonus() {
    return bonus;
}
public void setBonus(int bonus) {
    this.bonus = bonus;
}

}

Guys please help me to come out of this Exception.

1
  • 2
    And the stack trace of the exception is? Commented May 20, 2013 at 17:56

2 Answers 2

2

Include this as the second line in your file:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Sign up to request clarification or add additional context in comments.

Comments

0

There are maybe other errors, but this line is invalid:

<mapping resource="config\\employee.hbm.xml"/>>
                                              ^-- two brackets here

Also, the resource should be config/employee.hbm.xml. The resource is a classpath resource, using forward slashes as path separator.

2 Comments

While changing resourse to "config/employee.hbm.xml"> Still it is showing Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource config/employee.hbm.xml
And the full stack trace of the exception is?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.