Author
problem with hibernate
kishore nerella
Greenhorn
Joined: Jul 17, 2007
Posts: 15
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.
Arun Kumarr
Ranch Hand
Joined: May 16, 2005
Posts: 508
Are hibernate jars present in your classpath of the application?
If you are not laughing at yourself, then you just didn't get the joke.
kishore nerella
Greenhorn
Joined: Jul 17, 2007
Posts: 15
Everything is perfect but still it is giving same problem Is there any other solution for this.
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
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?
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
kishore nerella
Greenhorn
Joined: Jul 17, 2007
Posts: 15
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(); } }
Saathvik Reddy
Ranch Hand
Joined: Jun 03, 2005
Posts: 228
Check if you have hibernate.jar file in the lib directory!
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17243
posted Sep 28, 2007 08:50:00
0
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
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
subject: problem with hibernate