【问题标题】:Exception in thread "main" org.hibernate.MappingException: invalid configuration线程“主”org.hibernate.MappingException 中的异常:配置无效
【发布时间】:2013-05-20 17:43:40
【问题描述】:

您好,我在尝试运行我的休眠应用程序时遇到休眠异常。

我的 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 扩展雇员 {

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

}

请大家帮我摆脱这个例外。

【问题讨论】:

  • 而异常的堆栈跟踪是?

标签: java hibernate


【解决方案1】:

将此作为文件的第二行:

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

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 将资源更改为“config/employee.hbm.xml”"> 仍然在线程“main” org.hibernate.InvalidMappingException 中显示异常:无法从资源 config/employee.hbm 解析映射文档.xml
    • 异常的完整堆栈跟踪是?
    猜你喜欢
    • 2014-04-22
    • 2016-01-16
    • 1970-01-01
    • 2016-06-09
    • 2016-03-01
    • 2017-06-03
    • 2023-03-19
    • 1970-01-01
    • 2020-01-03
    相关资源
    最近更新 更多