• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate : Could not parse mapping document from resource

 
Srilu nandula
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still have this problem. Can anyone help?
 
Arun Rao
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic