wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Getting a org.hibernate.MappingNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Getting a org.hibernate.MappingNotFoundException" Watch "Getting a org.hibernate.MappingNotFoundException" New topic

Getting a org.hibernate.MappingNotFoundException

P Rajendra Prasad

Joined: Jul 25, 2012
Posts: 2

so i started learning hibernate, and i was writing my first program. I had everything in place, like i added all hibernate libraries, and placed hibernate.cfg.xml in src folder and i created a class "User" which i had to persist.
I had added that class to '<mapping>' tag (with fully qualified domain name).
But when i run the program, it shows up this....

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: org.test.www.model.User 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.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at org.test.www.impl.Driver.main(Driver.java:17)

and by the way, 'Driver' is my implementation class.

my hibernate.cfg.xml file is as below.....

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@//localhost:1521/XE</property>
<property name="hibernate.connection.username">HR</property>
<property name="hibernate.connection.password">tiger</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="org.test.www.model.User"></mapping>
please help me out, i really appreciate it.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

canyon quest wrote:Exception in thread "main" org.hibernate.MappingNotFoundException: resource: org.test.www.model.User not found.

So presumably "User" corresponds to a User class in your system? Then you need a Hibernate configuration file for that class in your project. In the same folder as your main Hibernate configuration file would be the best choice, I think.

Edit: I see you have this reference:

<mapping resource="org.test.www.model.User"></mapping>

In my configuration the "resource" attribute contains the name of the resource, not the name of the class it describes. So in my configuration it would look like this:

P Rajendra Prasad

Joined: Jul 25, 2012
Posts: 2

Thanks for the reply paul, but there is tiny problem. I am learning the hibernate through video tutorials, and if you see the following video "http://www.youtube.com/watch?v=3eXjpve0QaI&feature=relmfu", you will notice that there was no configuration of such .hbm resource file anywhere. I did everything that was shown in the video, but yet i get this error. please can you look into that.
tyte kyat
Ranch Hand

Joined: May 17, 2011
Posts: 40
I am also a newbie here.

But, I think I can point out your problem here.

you said you did mapping as follow

If I am right resource is used to map another XML format file. Here in your case, you have to use as follow

I agree. Here's the link: http://aspose.com/file-tools
subject: Getting a org.hibernate.MappingNotFoundException
Similar Threads
Nested exception: Content is not allowed in prolog
Automatic Schema Generation
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
Could not parse configuration: /hibernate.cfg.xml
Could not parse configuration: /hibernate.cfg.xml