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