【问题标题】:MappingNotFoundException in HibernateHibernate 中的 MappingNotFoundException
【发布时间】:2013-04-28 20:09:19
【问题描述】:

我已关注this 教程。

这是我的文件夹结构:

当我运行 App.Java 时,我得到:

Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: com/mkyong/user/DBUser.hbm.xml not found

但是,如您所见,我有那个文件。当我把文件放在

src/main/java/com/mykong/user/DBUser.hbm.xml

我仍然收到此错误。

我怎样才能使这个例子工作?

谢谢。

编辑:

hibernate.cfg.xml

<hibernate-configuration>
    <session-factory>

        <property name="connection.url">jdbc:mysql://localhost:3306/sampleapplication</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password">MYPASSWORDHERE</property>

        <property name="show_sql">true</property>
        <mapping resource="com/mkyong/user/DBUser.hbm.xml"></mapping>
    </session-factory>
</hibernate-configuration>

【问题讨论】:

  • 我们可以看看你的hibernate.cfg.xml
  • @blackpanther 谢谢,我已经编辑了我的问题。

标签: java hibernate


【解决方案1】:

知道了:拼写错误:在您的 hiberate.cfg.xml 文件中,您已指定休眠映射文件位于以下位置:com/mkyong/user/DBUser.hbm.xml 但是,在包目录结构中它是:com/mykong/user/DBUser.hbm.xml。注意mykong;不是mkyong。

因此,在hibernate.cfg.xml文件中,请尝试更改

<mapping resource="com/mkyong/user/DBUser.hbm.xml"></mapping>

到以下:

<mapping resource="com/mykong/user/DBUser.hbm.xml"></mapping>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 2011-01-13
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    相关资源
    最近更新 更多