-->
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.  [ 5 posts ] 
Author Message
 Post subject: invalid mapping exception
PostPosted: Sun May 13, 2007 8:34 am 
Newbie

Joined: Sun Apr 29, 2007 12:10 pm
Posts: 6
Location: vijayawada
while I'm doing hibernate application I'm getting error.Please anybody can help me?


I have placed hiberservlet.html in webapps/root


<html>
<body bgcolor="pink">
<form method=post
action="http://localhost:8080/servlet/hiberservlet">
Name :
<input type=text name="text1"> <br><br>
Place :
<input type=text name="text2"> <br><br>

Key ( for remove and find) :
<input type=text name="text3"> <br><br>

Operation :
<select name="combo1" >
<option value="add">Add
<option value="remove">Remove
<option value="find">Find
<option value="showall">Show All
</select> <br><br>
<input type=submit>
</form>
</body>
</html>


I have placed player.hbm.xml,Hibernate.cfg.xml,player.class,hiberservlet.class in root/WEB-INF/classes folder

player.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate-mapping DTD 3.2//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.2 dtd">
<hibernate-mapping>
<class name="player"
table="playertable">

<id name="id" type="int" column="ID"
unsaved-value="0">
<generator class="increment"/>
</id>

<property name="name" type="string">
<column name="name"/>
</property>
<property name="place" type="string">
<column name="place"/>
</property>
</class>

</hibernate-mapping>


hibernate.cfg.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate Configuration DTD 3.2//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.2 dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hiberdemo</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></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 resource="player.hbm.xml"/>
</session-factory>
</hibernate-configuration>


hiberservlet.java


import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class hiberservlet
extends HttpServlet
{
SessionFactory factory=null;

public void init()
{
try
{
Configuration cfg =
new Configuration();
cfg.addClass(player.class);

factory = cfg.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 c = req.getParameter("text3");
String s = req.getParameter("combo1");
DataInputStream dis=new DataInputStream(System.in);
Transaction tx = null;

if(s.equals("add"))
{
try
{
Session session = factory.openSession();

tx = session.beginTransaction();
player player1 = new player(a,b);
session.save(player1);
tx.commit();
session.flush();
session.close();

out.println("added");
}
catch(Exception e1)
{System.out.println(""+e1);}
}
//---------------------------------------
if(s.equals("remove"))
{
try
{
System.out.println("What key? ");
a = dis.readLine();

Session session = factory.openSession();

tx = session.beginTransaction();

int i = Integer.parseInt(a);

player player1 = (player)
session.get(player.class,new Integer(i));

session.delete(player1);
tx.commit();
session.flush();
session.close();

System.out.println("removed");
}catch(Exception e1)
{System.out.println(""+e1);}
}

//--------------------------------------
/*if(s.equals("showall"))
{
try
{
Session session = factory.openSession();

tx = session.beginTransaction();

java.util.List list1=
session.find("from player");

Iterator i=list1.iterator();

while(i.hasNext())
{
player player1 = (player)i.next();

System.out.println(player1.getId());
System.out.println(player1.getName());
System.out.println(player1.getPlace());
System.out.println("---------------");
}
tx.commit();
session.flush();
session.close();

}catch(Exception e1)
{System.out.println(""+e1);}
} */
if(s.equals("find"))
{
try
{
System.out.println("What key ");
a = dis.readLine();

Session session = factory.openSession();


tx = session.beginTransaction();


int i=Integer.parseInt(a);
player player1 = (player)
session.get(player.class,new Integer(i));


String n=player1.getName();
String m=player1.getPlace();

System.out.println(n+"\t"+m);
tx.commit();
session.flush();
session.close();


}catch(Exception e1)
{System.out.println(""+e1);}
}
}
}


I have created setcpath.bat and set the classpath

set classpath=.;G:\hibernate-3.2\lib\hibernate3.jar;G:\hibernate-3.2\lib\cglib-full-2.1.3.jar;G:\hibernate-3.2\lib\commons-collections-2.1.1.jar;G:\hibernate-3.2\lib\commons-logging-1.0.4.jar;G:\hibernate-3.2\lib\dom4j-1.6.1.jar;G:\hibernate-3.2\lib\ehcache-1.2.3.jar;G:\hibernate-3.2\lib\jdbc2_0-stdext.jar;G:\hibernate-3.2\lib\jta.jar;G:\hibernate-3.2\lib\log4j-1.2.11.jar;G:\hibernate-3.2\lib\xerces-2.6.2.jar;G:\hibernate-3.2\lib\xml-apis.jar;G:\hibernate-3.2\lib\commons-pool-1.2.jar;G:\hibernate-3.2\lib\commons-dpcp-1.2.1.jar;G:\hibernate-3.2\lib\mysql_connector_java_3[1].1.12_bin;G:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;

while I'm running on the tomcat 5.5
http://localhost:8080/hiberservlet.html page it was opening.While I'm entering the values and click the submit button it is showing the error


May 7, 2007 2:36:59 PM org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
May 7, 2007 2:37:00 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
May 7, 2007 2:37:00 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
May 7, 2007 2:37:35 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 7, 2007 2:37:35 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 828 ms
May 7, 2007 2:37:35 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 7, 2007 2:37:35 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.7
May 7, 2007 2:37:35 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
May 7, 2007 2:37:36 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(G:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\hiber\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
May 7, 2007 2:37:36 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[localhost].StandardContext[/hiber]
May 7, 2007 2:37:36 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(G:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
log4j:WARN No appenders could be found for logger (org.apache.catalina.session.ManagerBase).
log4j:WARN Please initialize the log4j system properly.
May 7, 2007 2:37:36 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 7, 2007 2:37:36 PM org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on /0.0.0.0:8009
May 7, 2007 2:37:36 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
May 7, 2007 2:37:36 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
May 7, 2007 2:37:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1344 ms
org.hibernate.InvalidMappingException: Could not parse mapping document from resource player.hbm.xml
java.lang.NullPointerException

Please can anybody help me


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 11:54 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi leela ,

this should be first line of HBM file.
<?xml version="1.0"?>
Check it

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: invalid mapping exception
PostPosted: Tue May 15, 2007 3:29 am 
Newbie

Joined: Sun Apr 29, 2007 12:10 pm
Posts: 6
Location: vijayawada
Pandey,

I have already placed the first line as


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

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

<id name="id" type="java.lang.Integer" column="ID"
unsaved-value="0">
<generator class="increment"/>
</id>

<property name="name" type="string" />
<property name="place" type="string" />
</class>

</hibernate-mapping>

Please look after


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 4:27 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi leela ,

could you try by change name as something else as playerName

change
<property name="name" type="string">
<column name="name"/>
</property>

to

<property name="playerName" type="string">
<column name="name"/>
</property>

Not sure

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 3:09 pm 
Newbie

Joined: Sun Apr 29, 2007 12:10 pm
Posts: 6
Location: vijayawada
could anybody please help me.I couldnot solve the problem.

How to solve the InvalidMappingException
java.lang.NullPointerException


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.