简体   繁体   English

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

[英]Exception in thread “main” org.hibernate.MappingException: invalid configuration

Hi Iam trying to run my hiberanate application i am getting the Hibernate Exception. 嗨,我试图运行我的hiberanate应用程序,我得到Hibernate异常。

my hibernate.cfg.xml file is 我的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 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 is Employee.java是

package com.javatpoint.mpackage;

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 Contract_Employee.java

package com.javatpoint.mpackage; package com.javatpoint.mpackage;

public class Contract_Employee extends Employee { 公共类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;
}

} }

Regular Employee.js is 常规Employee.js是

package com.javatpoint.mpackage;

public class Regular_Employee extends Employee { 公共类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;
}

} }

Guys please help me to come out of this Exception. 伙计们请帮助我摆脱这个例外。

Include this as the second line in your file: 将其作为文件中的第二行包含在内:

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

There are maybe other errors, but this line is invalid: 可能还有其他错误,但此行无效:

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

Also, the resource should be config/employee.hbm.xml . 此外,资源应该是config/employee.hbm.xml The resource is a classpath resource, using forward slashes as path separator. 资源是类路径资源,使用正斜杠作为路径分隔符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate:线程“ main” org.hibernate.MappingException中的异常:无效的配置 - Hibernate: Exception in thread “main” org.hibernate.MappingException: invalid configuration 线程“main”中的异常org.hibernate.MappingException:hibernate4中的配置无效 - Exception in thread “main” org.hibernate.MappingException: invalid configuration in hibernate4 线程“main”中的异常 org.hibernate.MappingException:未知实体 - Exception in thread "main" org.hibernate.MappingException: Unknown entity Hibernate org.hibernate.MappingException:无效的配置 - Hibernate org.hibernate.MappingException: invalid configuration 线程“main”中的异常org.hibernate.MappingException:未知实体: - Exception in thread “main” org.hibernate.MappingException: Unknown entity: 线程“ main” org.hibernate.MappingException中的异常:未知实体:Ville - Exception in thread “main” org.hibernate.MappingException: Unknown entity: Ville 线程“主” org.hibernate.MappingException中的异常:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数 - Exception in thread “main” org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister 线程“ main”中的异常org.hibernate.MappingException:未知实体:org.hibernate.internal.SessionImpl - Exception in thread “main” org.hibernate.MappingException: Unknown entity: org.hibernate.internal.SessionImpl 线程“main”中的异常org.hibernate.MappingException:未知实体:org.hibernate.employee - Exception in thread “main” org.hibernate.MappingException: Unknown entity: org.hibernate.employee 错误:线程“ main”中的异常org.hibernate.MappingException:未知实体:com.hibernate.demo.model.Contact - Error: Exception in thread “main” org.hibernate.MappingException: Unknown entity: com.hibernate.demo.model.Contact
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM