Hibernate中的MappingNotFoundException [英] MappingNotFoundException in Hibernate

查看:84
本文介绍了Hibernate中的MappingNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循这个教程。



以下是我的文件夹结构:


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

 创建初始SessionFactory failed.org.hibernate.MappingNotFoundException:资源:com / mkyong / user / DBUser.hbm.xml找不到

然而,我可以在那里看到那个文件。当我将该文件放在

  src / main / java / com / mykong / user / DBUser.hbm.xml $ b $下时b  

我仍然遇到这个错误。



谢谢。

编辑:

  hibernate.cfg.xml 

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


解决方案

明白了:拼写错误: $ c> hiberate.cfg.xml 文件指定hibernate映射文件驻留在以下位置: 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> 


I have followed this tutorial.

Here is my folder structure:

When I run App.Java, I get:

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

However, I have that file there as you can see it. When I put the file under

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

I am still getting this error.

How can I make this example work?

Thank you.

Edit:

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>

解决方案

Got it: Spelling error: In your hiberate.cfg.xml file you have specified that the hibernate mapping file resides in the location: com/mkyong/user/DBUser.hbm.xml However, in the package directory structure it is: com/mykong/user/DBUser.hbm.xml. Note the mykong; not mkyong.

Therefore, in the hibernate.cfg.xml file, please try changing

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

to the following:

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

这篇关于Hibernate中的MappingNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆