-->
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.  [ 2 posts ] 
Author Message
 Post subject: I got an error in eclipse
PostPosted: Tue Jul 03, 2012 3:09 pm 
Newbie

Joined: Tue Jul 03, 2012 3:05 pm
Posts: 2
SEVERE: Servlet.service() for servlet [studentInf] in context with path [/HibernateEX] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: net.sf.ehcache.CacheException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:323)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:219)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at com.example.StudentInf.service(StudentInf.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


Top
 Profile  
 
 Post subject: Re: I got an error in eclipse
PostPosted: Thu Jul 05, 2012 4:32 pm 
Newbie

Joined: Tue Jul 03, 2012 3:05 pm
Posts: 2
StudentInf.java
---------------

package com.example;
import javax.servlet.*;

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

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class StudentInf extends HttpServlet{

/**
*
*/
private static final long serialVersionUID = 1L;

public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{

PrintWriter out = response.getWriter();

String vid = request.getParameter("studentid");
String vname = request.getParameter("name");
String vage = request.getParameter("age");
String vcourse = request.getParameter("course");
String vaddress = request.getParameter("address");
SessionFactory sessionFactory = null;
Session session = null;
// sessionFactory = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
//session =sessionFactory.openSession();
System.out.println(vid);
try{
sessionFactory = new Configuration().configure("com/example/hibernate.cfg.xml").buildSessionFactory();

session =sessionFactory.openSession();


StudentHibernate sh = new StudentHibernate();

System.out.println(sh);
sh.setStudentid(Integer.parseInt(vid));
sh.setName(vname);
sh.setAge(Integer.parseInt(vage));
sh.setCourse(vcourse);
sh.setAddress(vaddress);


session.save(sh);
System.out.println("Done");


out.println("User Data Saved Successfully.......");
out.println("<a href=\"http://localhost:8080/Servlet Ex/New Registration Screen.jsp \"> click here to Add one more Employee Data.</a>");

}catch(Exception e){

System.out.println(e.getMessage());
}

}
}


StudentHibernate.java
---------------------
package com.example;

public class StudentHibernate{

int studentid;
String name;
int age;
String course;
String address;

public int getStudentid(){

return studentid;
}

public void setStudentid(int studentid){

this.studentid = studentid;

}

public String getName(){

return name;
}

public void setName(String name){

this.name = name;

}
public int getAge(){

return age;
}

public void setAge(int age){

this.age = age;

}
public String getCourse(){

return course;
}

public void setCourse(String course){

this.course = course;

}
public String getAddress(){

return address;
}

public void setAddress(String address){

this.address = address;

}

}

studenthibernate.hbm.xml
-------------------------
<?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="com.example.StudentHibernate" table="studenthibernate">
<id name="studentid" column="Studentid" >
<generator class="assined"/>
</id>
<property name="name" >
<column name="Name" />
</property>
<property name="age" >
<column name= "Age" />
</property>
<property name="course" >
<column name="Course"/>
</property>
<property name="address" >
<column name="Address"/>
</property>
</class>
</hibernate-mapping>

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://localhost:3306/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="com/example/studenthibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Thanq


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