-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Error reading resource: Exam
PostPosted: Tue Nov 08, 2005 7:11 am 
Newbie

Joined: Tue Nov 08, 2005 6:49 am
Posts: 2
hello everyone,
i am using hibernate for simple database operation but unable to apply it properly. i am using hibernate3.jar. whenever try to insert data from a form i got "org.hibernate.MappingException: Error reading resource: Example/player.hbm.xml" error in my log file. my code is

hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="Example.player.xml"/>
</session-factory>
</hibernate-configuration>

player.hbm.xml
<?xml version='1.0'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Example.player" table="table1">
<property name="name">
<column name="name" not-null="false"/>
</property>
<property name="place">
<column name="place" not-null="false"/>
</property>
<id name="id" sql-type="int" unsaved-value="null">
<column name="id" not-null="false"/>
<generator class="increment"/>
</id>
</class>
</hibernate-mapping>


where "test" is the name of database and "table1" is the name of table


on submiting data i got error:

Using properties file: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Itcora\log4j.properties
org.hibernate.MappingException: Error reading resource: Example/player.hbm.xml
java.lang.NullPointerException
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
Caused by: java.lang.NullPointerException
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:883)
at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1159)
at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1131)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:312)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1053)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1065)
at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:447)
at org.apache.catalina.core.StandardService.stop(StandardService.java:512)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:714)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:590)
at org.apache.catalina.startup.Catalina.start(Catalina.java:565)
... 6 more


can anyone help me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 7:42 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Yes.

Your mapping resource is wrong.


It should be

example/player.hbm.xml


not example.player.hbm.xml

and only then if player.hbm.xml is in the directory example.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 7:44 am 
Newbie

Joined: Fri Nov 04, 2005 12:51 pm
Posts: 5
Hi!

Try this:

in the hibernate.cfg.xml:

<mapping resource="Example/player.xml"/>


in the player.hbm.xml

<hibernate-mapping>
<class name="player" table="table1">



The hibernate.cfg.xml should stay in a package before the Example package and the player.hbm.xml inside the Example package.

Like this:

c:/hibernate.cfg.xml
c:/Example/player.xml

Hope it helps!

[]'s


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 9:09 am 
Newbie

Joined: Tue Nov 08, 2005 6:49 am
Posts: 2
thankx for help.
but the problem is still there. Actually i am working in tomcat 5.5. my hibernate.cfg.xml is in application's \WEB-INF\classes folder and my player.hbm.xml is in application's \WEB-INF\classes\Example folder.

for troubleshooting i change the name of mapping resource in hibernate.cfg.xml but the error shows previous file name.

i am really so confused. now i am sending you the whole structure of my application

hibernate.cfg.xml in \WEB-INF\classes folder
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="Example/player.hbm.xml"/>
</session-factory>
</hibernate-configuration>

player.hbm.xml in \WEB-INF\classes\Example folder

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="player" table="table1">
<property name="name">
<column name="name" not-null="false"/>
</property>
<property name="place">
<column name="place" not-null="false"/>
</property>
<id name="id" sql-type="int" unsaved-value="null">
<column name="id" not-null="false"/>
<generator class="increment"/>
</id>
</class>
</hibernate-mapping>

player.java & player.class in \WEB-INF\classes\Example folder

package Example;
public class player
{
private String name;
private String place;
private int id;
public player() { }
public player(String a,String b)
{
name=a;
place=b;
}
public String getName()
{
return name;
}
public void setName(String a)
{
name = a;
}
public String getPlace()
{
return place;
}
public void setPlace(String b)
{
place = b;
}
public int getId()
{
return id;
}
public void setId(int s)
{
id = s;
}
}

hiberservlet.java & hiberservlet.class in \WEB-INF\classes\Example folder
package Example;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
public class hiberservlet extends HttpServlet
{
Session session=null;
SessionFactory factory=null;
public void init()
{
try
{
Configuration cfg = new Configuration();
cfg.addClass(player.class);
factory = cfg.configure().buildSessionFactory();
System.out.println("factory ready");
}
catch(Exception e1)
{
System.out.println(""+e1);
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String a = req.getParameter("text1");
String b = req.getParameter("text2");
String s = req.getParameter("combo1");
Transaction tx = null;
if(s.equals("add"))
{
try
{
session = factory.openSession();
tx = session.beginTransaction();
player player1 = new player();
player1.setId(6);
player1.setName(a);
player1.setPlace(b);
session.save(player1);
tx.commit();
session.flush();
session.close();
out.println("<html>");
out.println("<head><title>hibernate</title></head>");
out.println("<body>");
out.println("Record Added");
out.println("</body>");
out.println("</html>");
}
catch(Exception e1)
{
System.out.println(""+e1);
}
}
}
}

i think you can understand my problem.
if you have some servlet based hibernate example then please send it to my mail address.
my mail id is pali_253@yahoo.co.in

Regards:
Abhishek Paliwal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.