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.  [ 1 post ] 
Author Message
 Post subject: Problem running a Servlet using Hibernate
PostPosted: Sun Jul 22, 2007 10:23 pm 
Newbie

Joined: Sun Jul 22, 2007 9:59 pm
Posts: 4
Hi,
I am using Hibernate3.2 with MySql Server 5.0.

I have written the following Servlet code

Code:
[color=darkred]import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.hibernate.*;
import org.hibernate.cfg.*;
import org.hibernate.SessionFactory.*;

import employee.Department;

public class departmentTest extends HttpServlet {

    private SessionFactory sessionFactory;
   
    public void init(ServletConfig config) throws ServletException
    {

   super.init(config);
   try{
      sessionFactory = new Configuration().addClass(Department.class).buildSessionFactory();
      

   }catch(Exception e)
   {
      e.printStackTrace();
   }   


    }

    private void displayAll(PrintWriter out, Session session)
    {
   try {
   
      out.println("<html>");
      out.println("<table border = '1'>");
      out.println("<tr><th>Department ID</th><th>Name</th></tr>");

      List depts = session.find("from departments");
   
      Iterator iter =  depts.iterator();
      while(iter.hasNext())
      {

         Department dept = (Department)iter.next();         
         out.println("<tr><td>");
         out.println(dept.getId());
         out.println("</td><td>");
         out.println(dept.getName());
         out.println("</td><tr>");

      }
   }catch(Exception e)
   {
      e.printStackTrace();
   }
    }         
       
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
       
   Session session=null;
   
   try{
      session=sessionFactory.openSession();
      
      String action = request.getParameter("submit");
      if(action.equals("Get Departments"))
      {
         displayAll(out, session);
   
      }
      else
         out.println("Bad Input");
   
      session.flush();
      session.close();      

   }catch(Exception e)
   {
      e.printStackTrace();
   }
    }



public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
   doGet(request,response)   ;
}
}[/color]


When i try to complile this Java File I get the following error traces:
Code:
[color=darkred]C:\shivali\shivali\Tomcat 5.0\webapps\shivaliTest>javac departmentTest.java
departmentTest.java:7: cannot access org.hibernate.SessionFactory
bad class file: C:\hibernate-3.2\hibernate3.jar(org/hibernate/SessionFactory.cla
ss)
class file has wrong version 48.0, should be 47.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
import org.hibernate.SessionFactory.*;
                     ^
1 error[/color]

_________________
Regards
Shivali Goel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.