Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

simple database insertion program in Servlet using Hibernate  RSS feed

 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when i run the program i get the following error... Please Help..

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
org.Servlet.Personal_Details.doGet(Personal_Details.java:117)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause

java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
org.Servlet.Personal_Details.doGet(Personal_Details.java:117)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.14 logs.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you add all the required jars to your WEB-INF/lib? (Hint: you didn't.)
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep i created a new user library named "Hibernate" and inserted all the required jar into it.
Following are the name of Jars file

antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.0.Beta5.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
hibernate-osgi-4.3.0.Beta5.jar
org.osgi.core-4.3.1.jar
hibernate-entitymanager-4.3.0.Beta5.jar
hibernate-envers-4.3.0.Beta5.jar
mysql-connector-java-5.0.8-bin.jar
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what a "user library" is, but all required jar files need to go into the WEB-INF/lib directory of your web app.

Which of those files contains the missing class?
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ulf Dittmer
As you told me i imported all the required jars into lib folder..But i get following error

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Error reading configuration file
java.util.ServiceLoader.fail(ServiceLoader.java:224)
java.util.ServiceLoader.parse(ServiceLoader.java:301)
java.util.ServiceLoader.access$200(ServiceLoader.java:181)
java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:349)
java.util.ServiceLoader$1.hasNext(ServiceLoader.java:432)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:338)
org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:215)
org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:71)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1909)
org.Servlet.Personal_Details.doGet(Personal_Details.java:117)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause

java.io.FileNotFoundException: D:\Stay Out!! (The system cannot find the file specified)
java.util.zip.ZipFile.open(Native Method)
java.util.zip.ZipFile.<init>(ZipFile.java:214)
java.util.zip.ZipFile.<init>(ZipFile.java:144)
java.util.jar.JarFile.<init>(JarFile.java:152)
java.util.jar.JarFile.<init>(JarFile.java:89)
sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:98)
sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
java.net.URL.openStream(URL.java:1035)
java.util.ServiceLoader.parse(ServiceLoader.java:296)
java.util.ServiceLoader.access$200(ServiceLoader.java:181)
java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:349)
java.util.ServiceLoader$1.hasNext(ServiceLoader.java:432)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:338)
org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:215)
org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:71)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1909)
org.Servlet.Personal_Details.doGet(Personal_Details.java:117)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think that error message means, and how you might go about investigating and fixing the problem?
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is due to SessionFactory...but i dont know how do i resolve this..although i imported all the jars in my project..
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here Is my Source Code


package org.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

/**
* Servlet implementation class PersonalDetails
*/
@WebServlet("/Personal_Details")
public class Personal_Details extends HttpServlet {
private static final long serialVersionUID = 1L;


@Id
@Column(name="EMPLOYEE_ID")
private int employeeId;

@Column(name="FIRST_NAME")
private String firstName;

@Column(name="LAST_NAME")
private String lastName;

@Column(name="EMAIL")
private String email;

@Column(name="PASSWORD")
private String password;

/*.......................................................*/

public int getEmployeeId() {
return employeeId;
}

public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}



protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Personal_Details person=new Personal_Details();
try{

response.setContentType("text/html");
PrintWriter out=response.getWriter();

out.println("Hello Worlds");

int emp_id=Integer.parseInt(request.getParameter("id"));
String emp_fname=request.getParameter("fname");
String emp_lname=request.getParameter("lname");
String emp_email=request.getParameter("email");
String emp_password=request.getParameter("password");


person.setEmployeeId(emp_id);
person.setFirstName(emp_fname);
person.setLastName(emp_lname);
person.setEmail(emp_email);
person.setPassword(emp_password);
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
try{
@SuppressWarnings("deprecation")
SessionFactory sessionfactory=new Configuration().configure().buildSessionFactory();//Error Line
Session session=sessionfactory.openSession();
session.beginTransaction();
session.save(person);
session.getTransaction().commit();
session.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}

}

}







 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tushar Gosalia wrote:The error is due to SessionFactory

No. It is also not a problem related to the source code.

This is what I said earlier:
Ulf Dittmer wrote:all required jar files need to go into the WEB-INF/lib directory of your web app.

Which of those files contains the missing class?

Can you answer that last question? Is that file really in WEB-INF/lib? (NOT in a "user library", NOT "imported into the project" - in the WEB-INF/lib directory).
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes..here is the Directory Structure

WebContent
| |
META-INF WEB-INF
|
lib
|
antlr-2.7.7.jar
|
dom4j-1.6.1.jar
|
hinernate-commons-annotations.jar
|
hibernate-core.jar
|
hibernate-entitymanager.jar
|
hibernate-envers.jar
|
hibernate-jpa.jar
|
hibernate-osgi.jar
|
javassist.jar
|
jboss-logging.jar
|
jboss-transaction.jar
|
org.osgi.core.jar



 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the answer to this question:
Which of those files contains the missing class?

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.io.FileNotFoundException: D:\Stay Out!! (The system cannot find the file specified)

Erm, do you know anything about this file? It is part of your stacktrace you provided earlier.
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No what is it...and what i need to do for java.io.FileNotFoundException
 
vijay jamadade
Ranch Hand
Posts: 244
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tushar, If some class is missing here. you need to find out related jar for it. Thats what people are trying to tell you indirectly. these are common errors you need to develop technique of solving these issues.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!