• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with hibernate

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys
I'm working a hibernate application to insert student details in the database.But it it giving exception as

Exception:
javax.servlet.ServletException: Error instantiating servlet class InsertStudent

RootCause:
java.lang.NoClassDefFoundError: org/hibernate/Session

can anyone please help me.
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are hibernate jars present in your classpath of the application?
 
kishore nerella
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything is perfect but still it is giving same problem
Is there any other solution for this.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kishore nerella:
Everything is perfect but still it is giving same problem
Is there any other solution for this.



No. You need to make sure the Hibernate jars are in your application's classpath. A java.lang.NoClassDefFoundError occurs when the class loader tries to load a class it cannot find. Where have you put the Hibernate jar files?
 
kishore nerella
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem is really killing me.
can you please check out all the programs i have written and find the error.

Student.jsp
<html>
<body>
<center><h2>Student Insertion Form</h2></center>
<form action="StudentInsert">
<table>
<tr>
<td>
Student No:
</td>
<td>
<input type="text" name="sno">
</td>
</tr>
<tr>
<td>
Student Name:
</td>
<td>
<input type="text" name="sname">
</td>
</tr>
<tr>
<td>
Student Email:
</td>
<td>
<input type="text" name="email">
</td>
</tr>
<tr>
<td>
Student Mobile:
</td>
<td>
<input type="text" name="mobile">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Insert">
</td>
</tr>
</table>
</form>
</body>
</html>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
InsertStudent</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>InsertServlet</servlet-name>
<servlet-class>InsertStudent</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InsertServlet</servlet-name>
<url-pattern>/StudentInsert</url-pattern>
</servlet-mapping>
</web-app>

hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- postgresql configuration -->
<property name="connection.url">jdbc dbc:kishdsn</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<mapping resource="stud/student.hbm.xml" />
</session-factory>
</hibernate-configuration>

student.hbm.xml
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="stud">
<class name="Student" table="student">
<id name="sno" column="sno" type="java.lang.Integer">
<generator class="assigned"/>
</id>
<property name="sname" column="sname" type="java.lang.String" />
<property name="email" column="email" type="java.lang.String" />
<property name="mobile" column="mobile" type="java.lang.Integer"/>
</class>
</hibernate-mapping>


student.java




import java.io.Serializable;

public class Student implements Serializable
{
private int sno,mobile;
private String sname,email;

public Student()
{

}

public void setSno(int sno)
{
this.sno=sno;
}
public void setSname(String sname)
{
this.sname=sname;
}
public void setEmail(String email)
{
this.email=email;
}
public void setMobile(int mobile)
{
this.mobile=mobile;
}

public int getSno()
{
return this.sno;
}
public String getSname()
{
return this.sname;
}
public String getEmail()
{
return this.email;
}
public int getMobile()
{
return this.mobile;
}

}

InsertStudent.java
import org.hibernate.*;
import org.hibernate.cfg.*;
public class InsertStudent
{
public static void main(String args[]) throws Exception
{
Configuration c=new Configuration();
c.configure("hibernate.cfg.xml");
SessionFactory sf=c.buildSessionFactory();
Session s=sf.openSession();
Transaction tx=s.beginTransaction();

Student sb=new Student();

sb.setSno(Integer.parseInt(args[0]));
sb.setSname(args[1]);
sb.setEmail(args[2]);
sb.setMobile(Integer.parseInt(args[3]));

s.save(sb);
s.flush();
tx.commit();
System.out.println("Record inserted");
s.close();
}
}
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check if you have hibernate.jar file in the lib directory!
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error is not related to any code or mapping or xml files that you have, it is just that the jar file is not in the classpath.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic