线程“main”中的异常org.hibernate.MappingException:配置无效

时间:2013-05-20 17:43:41

标签: java hibernate

嗨,我试图运行我的hiberanate应用程序,我得到了Hibernate Exception。

我的hibernate.cfg.xml文件是

<?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是

package com.javatpoint.mpackage;

公共类员工{

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;

公共类Contract_Employee扩展了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;
}

}

常规Employee.js是

package com.javatpoint.mpackage;

公共类Regular_Employee扩展了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;
}

}

伙计们请帮助我摆脱这个例外。

2 个答案:

答案 0 :(得分:2)

将其作为文件中的第二行包含在内:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

答案 1 :(得分:0)

可能还有其他错误,但此行无效:

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

此外,资源应为config/employee.hbm.xml。资源是类路径资源,使用正斜杠作为路径分隔符。