File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Author

Hibernate : Could not parse mapping document from resource

Srilu nandula
Greenhorn

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"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<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"/>

</session-factory>
</hibernate-configuration>

Hibernate mappings file: Consumer.hbm.xml

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

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="Hibernate">
<class
name="Consumer"
table="consumer">

<id
name="id"
column="CONSUMER_ID">
<generator class="native"/>
</id>

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

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

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

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

<property
name = "dateRegistered"
column = "DATE_REGISTERED"
type = "date"/>

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

</class>
</hibernate-mapping>

Consumer.java

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) {
this.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) {
this.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,
Srilu
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
Greenhorn

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
Greenhorn

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
Greenhorn

Joined: Aug 26, 2008
Posts: 2
Hello.

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate : Could not parse mapping document from resource
 
Similar Threads
Joining tables
Problem in <one-to-one> relation mapping
Hibernate Issue
Batch Delete Problem
MappingNotFoundException