The moose likes Object Relational Mapping and the fly likes Hibernate + Configuration.addClass Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate + Configuration.addClass Exception" Watch "Hibernate + Configuration.addClass Exception" New topic

Hibernate + Configuration.addClass Exception

Steve Press

Joined: Oct 08, 2004
Posts: 1
Hello all!

I have a following problem with Hibernate application which I develope in
Eclipse environment.

Application is a simple Java standalone program and it has
hibernate.cfg.xml file and a class for mapping a class to DB.

Hibernate.cfg.xml file is read without problems but
everytime in code when Configure class is invoking addClass-method
MappingException is thrown.

08-Oct-2004 10:57:22 net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: hibertest/Product.hbm.xml
Exception in thread "main" net.sf.hibernate.MappingException: Resource: hibertest/Product.hbm.xml not found
at net.sf.hibernate.cfg.Configuration.addClass(
at hibertest.HibTestMain.main(

I have strugled with this 2 and half days

Where does Hibernate actually reads XML mapping files?

I have put all my XML files to same place which is in the root of
Eclipse project so, if hibernate.cfg.xml is found should'n mapping XMLs found too?

I have following hibernate.cfg.xml file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"

<property name="hibernate.connection.url">
jdbc ostgresql://localhost/TesterDB
<property name="show_sql">false</property>
<property name="hibernate.connection.driver_class">
<property name="dialect">
<property name="hibernate.connection.username">usepostg</property>
<property name="hibernate.connection.password" />
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.transaction.factory_class">
<!-- Mapping files -->
<mapping resource="Product.hbm.xml" />

and Product.hbm.xml file for class OR mapping is:

?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"

<class name="hibertest.Product" table="Product">

<id name="id" type="string"
<column name="id" sql-type="varchar(32)"
<generator class="uuid.hex"/>
<property name="name" type="java.lang.String">
<column name="name" sql-type="varchar(32)"
<property name="price" type="java.lang.Double">
<column name="price" sql-type="int8"
<property name="amount" type="java.lang.Long">
<column name="amount" sql-type="int4"
bamini mini

Joined: May 05, 2004
Posts: 3

when you give the name of your column in hbm file, it must be different from the column name.

you dont give the same name for property name and column name.

for eg.

<property name="name" column="studentName"/>

both column nameand property name mustnot be same.

and when you are writting the jave file for getting property

u call the getterfile and setterfile like this.
public string getName()
return name;}
public void setName(String value)

ok change the property name in hbm should give different name from the column name

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

when you give the name of your column in hbm file, it must be different from the column name.

Hmm. Not sure why you think this, but its not the case. There is nothing to stop you giving property names the same values as DB field names.

Try putting product.hbm.xml in the same place as your product.class file (which I assume is in the directory "hibertest").
[ October 11, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Madhu Kumar Vatts
Ranch Hand

Joined: Apr 01, 2004
Posts: 74
hey steve,

I got similar problem when I was trying to debug my application using Eclipse. It was throwing the mapping file not found exception. I solved it by placing the files in the class path. hope it helps you.

Let me know if you have questions or if this helped you


Oracle Certified Enterprise Architect (Part 1);SUN Certified Programmer;SUN Certified Business Component Developer;SUN Certified Web Component Developer;
Oracle Certified WebServices Developer;Oracle Certified Java Persistence API Developer;Oracle Certified SQL Expert;IBM Certified XML Solution Developer
Madhu Kumar Vatts
Ranch Hand

Joined: Apr 01, 2004
Posts: 74

I thought I will give you some more information which might help you in solving your problem
I will describe little how my application layers are divided and how hibernate loads the hibernate.cfg.xml file and corresponding mapping files.

I have these directories
1. cfg -> where all the mapping files are present(hibernate.cfg.xml, *.hbm.xml)
2. lib
3. src -> Main source code from which mapping files are called
4. bin

This is the way I call the mapping files
import net.sf.hibernate.cfg.Configuration;
private static final Configuration cfg = new Configuration();
this loads all the necessary mapping files necessary for me.

Let me know if this helps

Peter Boyle

Joined: Oct 27, 2004
Posts: 1
I am having weird problem. My Person.hbm.xml is next to hibernate.cfg.xml, and upon loading hibernate.cfg.xml (which has reference to Person.hbm.xml), I get the exception that Person.hbm.xml has not found.

Has anyone know the solution to this problem? I am using Tomcat 3.3, does that matter?
I agree. Here's the link:
subject: Hibernate + Configuration.addClass Exception
It's not a secret anymore!