Java MappingNotFoundException:资源:找不到 user.hbm.xml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23605638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:16:47  来源:igfitidea点击:

MappingNotFoundException: resource: user.hbm.xml not found

javahibernate

提问by user3598351

enter image description hereHi i am tying to make simple web application for user registration form using jsp and hibernate When i run my application i am getting following Exeption

在此处输入图片说明嗨,我正在尝试使用 jsp 和 hibernate 为用户注册表制作简单的 Web 应用程序当我运行我的应用程序时,我正在关注 Exeption

MappingNotFoundException: resource: user.hbm.xml not found

Here is My code

这是我的代码

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
**hibernate.cfg.xml**
    <hibernate-configuration>

          <session-factory>
            <property name="hbm2ddl.auto">update</property>
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="connection.url">jdbc:mysql://localhost:3306/employee</property>
            <property name="connection.username">root</property>
            <property name="connection.password"></property>
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="show_sql">true</property>
        <mapping resource="hiber/user.hbm.xml"/>
        </session-factory>

    </hibernate-configuration>

user.hbm.xml

用户名.hbm.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

          <hibernate-mapping>
          <class name="User" table="u400">
          <id name="id">
          <generator class="increment"></generator>
          </id>
          <property name="name"></property>
          <property name="password"></property>
          <property name="email"></property>
          </class>
          </hibernate-mapping>

project Structure is as following

项目结构如下

 Project
    |
    |-WebPages
    |
    |-src
    |-hiber
    |  |-user.java
       |-UserDao.java
       |-user.hbm.xml
       |-hibernate.cfg.xml

How can i remove this Exception and what should i do

我怎样才能删除这个异常,我应该怎么做

Thanks in advance getting following Exception

提前感谢获得以下异常

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: org.hibernate.HibernateException: Could not parse configuration: /hiber/hibernate.cfg.xml

root cause

org.hibernate.HibernateException: Could not parse configuration: /hiber/hibernate.cfg.xml

root cause

org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net

采纳答案by Karibasappa G C

check the jar version of hibernate and compare it with DTD version inside hibernate.cfg.xml

检查hibernate的jar版本并与里面的DTD版本进行比较 hibernate.cfg.xml

it should match basically otherwise it can not resolve the dependencies.

它应该基本匹配,否则它无法解决依赖关系。

回答by Anshu Kunal

Can you try to give full path for your user.hbm.xml in hibernate.cfg.xml.

您能否尝试在 hibernate.cfg.xml 中为您的 user.hbm.xml 提供完整路径。

<mapping resource="hiber/user.hbm.xml"/>

回答by Tell Me How

Don't use full path in mapping resource :

不要在映射资源中使用完整路径:

<mapping resource="user.hbm.xml"/>

instead of

代替

<mapping resource="hiber/user.hbm.xml"/>

Its work for me hopefully for you.

它对我有用,希望对你有用。

回答by Anupam

Silly mistake:- your pojo/persistent class has "User.java" name which begins with capital 'U' but the mapping file "user.hbm.xml" begins with small 'u'. Solution:- both names should be same. eg:- "User.java" and "User.hbm.xml". -- Happy Coding.

愚蠢的错误:- 您的 pojo/persistent 类具有以大写“U”开头的“User.java”名称,但映射文件“user.hbm.xml”以小写“u”开头。解决方案:- 两个名称应该相同。例如:-“User.java”和“User.hbm.xml”。——快乐编码。

回答by inter18099

If you use Maven, put your hbm.xmlfile into resource folder under:

如果您使用 Maven,请将您的hbm.xml文件放入以下资源文件夹中:

/resource/[your package]/hbm.xml

/resource/[your package]/hbm.xml