-2

嗨,我得到了例外:

线程“主”org.hibernate.InvalidMappingException 中的异常:无法从资源employee.hbm.xml 解析映射文档

employee.hbm.xml 是:

这是 tablepersubclass 层次结构配置文件:

<hibernate-mapping package = "com.javatpoint.mypackage">
    <class name = "Employee" table = "Employee">
        <id name = "id" column = "eid">
        <generator class = "increment"></generator>
        </id>
        <property name = "name"  column = "name"></property>

        <joined-subclass name = "Regular_Employee" table = "RegEmployee">
            <key column = "eid"></key>
            <property name = "salary" column = "salary"></property>
            <property name = bonus column = "bonus"> </property>
        </joined-subclass>

        <joined-subclass name = "Contract_Emloyee"  table = "ConEmployee">
            <key column = "eid"> </key>
            <property name = "pay_per_hour" name = "pay_per_hour"></property>
            <property name = "contract_duration" name = "contract_duration"></property>
        </joined-subclass>

    </class>
</hibernate-mapping>

而配置文件hibernate.cfg.xml文件为:

<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="employee.hbm.xml"/>
</session-factory>

Employee.java 是:

package com.javatpoint.mypackage;

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.mypackage;

public class Contract_Emloyee extends Employee{

private float pay_per_hour;
private String contract_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 getContract_duration() {
    return contract_duration;
}
public void setContract_duration(String contract_duration) {
    this.contract_duration = contract_duration;
}

}

Regular_Employee.java 是:

package com.javatpoint.mypackage;

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

}

4

1 回答 1

4

employee.hbm.xml的 xml 无效。

<property name= bonus column="bonus"></property>

将其更改为:

<property name="bonus" column="bonus"></property>
于 2013-05-23T17:05:12.427 回答