0

嗨,我正在尝试运行我的休眠应用程序,但我遇到了休眠异常。

我的 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>

员工.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

包 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扩展员工{

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;
}

}

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

4

2 回答 2

2

将此作为文件中的第二行包括在内:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
于 2013-06-06T23:02:31.173 回答
0

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

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

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

于 2013-05-20T17:58:13.587 回答