您好我得到了例外:
线程“main”中的异常org.hibernate.InvalidMappingException:无法解析资源employee.hbm.xml中的映射文档
employee.hbm.xml是:
这里是tablepersubclass Hierarchy配置文件:
<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;
}
}
答案 0 :(得分:4)
您的employee.hbm.xml
无效xml。
<property name= bonus column="bonus"></property>
将其更改为:
<property name="bonus" column="bonus"></property>