Java org.hibernate.MappingNotFoundException

Java org.hibernate.MappingNotFoundException,java,hibernate,Java,Hibernate,我正在尝试做一个简单的hibernate程序。我正在按照本文中给出的步骤进行操作 我得到的错误是 org.hibernate.MappingNotFoundException: resource: org.manu.dtd.UserDetails not found at org.hibernate.cfg.Configuration.addResource(Configuration.java:799) at org.hibernate.cfg.Configuration

我正在尝试做一个简单的hibernate程序。我正在按照本文中给出的步骤进行操作

我得到的错误是

   org.hibernate.MappingNotFoundException: resource: org.manu.dtd.UserDetails not found
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:799)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2344)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2310)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2290)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2243)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
    at org.manu.dtd.TestHibernate.main(TestHibernate.java:16)
这是我的文件夹结构

我的带注释的persistence类是

package org.manu.dtd;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class UserDetails {

    @Id
    private int userId;

    private String userName;
    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

}
我的hibernate.cfg.xml文件是

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

<hibernate-configuration>

    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
        <property name="connection.username">user</property>
        <property name="connection.password">password</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <mapping resource="org.manu.dtd.UserDetails"/>

    </session-factory>

</hibernate-configuration>

任何人都可以帮助我解决这个问题。

为hibernate配置映射文件提供完全限定的名称

SessionFactory sF = new Configuration().
            configure("/org/manu/dtd/hibernate.cfg.xml").buildSessionFactory();

看来可以更容易地修复。您应该使用
而不是
,因为资源用于映射描述实体等的其他xml文件。这是官方教程中的一个小例子

当我像上面提到的那样放置路径时,错误是线程“main”org.hibernate.hibernate Exception:/org/manu/dtd/hibernate.cfg.xml中的
异常未找到
我应用了上述修复,并将此
放入hibernate.cfg.xml文件中,效果非常好,谢谢。
SessionFactory sF = new Configuration().
            configure("/org/manu/dtd/hibernate.cfg.xml").buildSessionFactory();