0

I have followed this tutorial.

Here is my folder structure:

enter image description here

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

1 回答 1

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>
于 2013-04-28T20:18:14.923 回答