File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate : Could not parse mapping document from resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate : Could not parse mapping document from resource " Watch "Hibernate : Could not parse mapping document from resource " New topic

Hibernate : Could not parse mapping document from resource

Srilu nandula

Joined: Dec 07, 2007
Posts: 7
I got this error message when I tried to enter a new row in my database table.

Here's my hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<session-factory name = "java:comp/env/hibernate/SessionFactory">
<property name="connection.datasource">jdbc/oracle</property>

<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<mapping resource="Hibernate/Consumer.hbm.xml"/>


Hibernate mappings file: Consumer.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "">

<hibernate-mapping package="Hibernate">

<generator class="native"/>


name = "address"
column = "ADDRESS"/>

name = "homePhone"
column = "HOME_PHONE"/>

name = "mobilePhone"
column = "MOBILE_PHONE"/>

name = "dateRegistered"
type = "date"/>

name = "dateModified"
column = "DATE_MODIFIED"
type ="date"/>


package Hibernate;
import java.util.Date;
public class Consumer {
private String id;
private String name;
private String address;
private String homePhone;
private String mobilePhone;
private Date dateRegistered;
private Date dateModified;

public Consumer() {}

public String getName() {
return name;
public void setName(String name) { = name;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address = address;
public String getHomePhone() {
return homePhone;
public void setHomePhone(String homePhone) {
this.homePhone = homePhone;
public String getMobilePhone() {
return mobilePhone;
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
public Date getDateRegistered() {
return dateRegistered;
public void setDateRegistered(Date dateRegistered) {
this.dateRegistered = dateRegistered;
public Date getDateModified() {
return dateModified;
public void setDateModified(Date dateModified) {
this.dateModified = dateModified;

private void setId(String id) { = id;

public String getId() {
return id;


Please let me know what could be the problem. If my application is not able to connect to the database will it be able to parse the configuration and mapping files? I am trying to figure out if the problem is in the code/syntax or is it because its not able to connect to the database.

Thank you,
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

The file probably isn't in your RUNTIME classpath. It might be in your build time classpath, but not at runtime.

Is it a web app? Make sure the file is in the \classes directory under web-inf at deployment time.

-Cameron McKenzie
Srilu nandula

Joined: Dec 07, 2007
Posts: 7
Thank you for the reply. It is a web application. My configuration file is under classes and mapping file is in the same directory as consumer.class
Srilu nandula

Joined: Dec 07, 2007
Posts: 7
I still have this problem. Can anyone help?
Arun Rao
Ranch Hand

Joined: Jan 23, 2004
Posts: 41
do you have the hibernate package? and a path like this?

<mapping resource="Hibernate/Consumer.hbm.xml"/>

As Cameron said it looks like the resource is not available at run time. Did you try to debug and what is the error you get? If possible post the stack trace.
Michael Li

Joined: Aug 26, 2008
Posts: 2

ich think your mapping to Document is not correct.
Are the fields compare to DB correct?

the ressource should placed in "Hibernate/Consumer.hbm.xml".

Have you already as sequence defined in Oracle?

Have you more lines of your log?
Consider Paul's rocket mass heater.
subject: Hibernate : Could not parse mapping document from resource
It's not a secret anymore!