2 Replies Latest reply: Apr 29, 2008 3:52 AM by 843844 RSS

    Compile Failed(Hibernate Tutorial)

    843844
      Hi,
      I'm trying steps of hibernate Tutorial from hibernate.org site.
      when i use ant war on command line I face some problem.
      C:\hibernateTutorial>ant war
      Buildfile: build.xml
      
      clean:
         [delete] Deleting directory C:\hibernateTutorial\bin
          [mkdir] Created dir: C:\hibernateTutorial\bin
      
      copy-resources:
           [copy] Warning: events\Event.hbm.xml modified in the future.
           [copy] Warning: events\Person.hbm.xml modified in the future.
           [copy] Warning: log4j.properties modified in the future.
           [copy] Warning:  modified in the future.
           [copy] Warning: util modified in the future.
           [copy] Copying 4 files to C:\hibernateTutorial\bin
           [copy] Copied 2 empty directories to 1 empty directory under C:\hibernateTu
      torial\bin
      
      compile:
          [javac] Warning: events\Event.hbm.xml modified in the future.
          [javac] Warning: events\Event.java modified in the future.
          [javac] Warning: events\EventManager.java modified in the future.
          [javac] Warning: events\Person.hbm.xml modified in the future.
          [javac] Warning: log4j.properties modified in the future.
          [javac] Warning: util\HibernateUtil.java modified in the future.
          [javac] Compiling 5 source files to C:\hibernateTutorial\bin
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:39: illegal
       start of expression
          [javac] private void printEventForm(PrintWriter out)
          [javac] ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:51: ';' exp
      ected
          [javac] List result = HibernateUtil.getSessionFactory().getCurrentSession().
      createCriteria(Event.class).list();
          [javac]
                           ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:51: <identi
      fier> expected
          [javac] List result = HibernateUtil.getSessionFactory().getCurrentSession().
      createCriteria(Event.class).list();
          [javac]
                                ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:51: '{' exp
      ected
          [javac] List result = HibernateUtil.getSessionFactory().getCurrentSession().
      createCriteria(Event.class).list();
          [javac]
                                        ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:52: illegal
       start of type
          [javac] if(result.size()>0)
          [javac] ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:70: <identi
      fier> expected
          [javac] }
          [javac] ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:71: illegal
       start of expression
          [javac] protected void createAndStoreEvent(String title,Date theDate)
          [javac] ^
          [javac] C:\hibernateTutorial\src\events\EventManagerServlet.java:78: ';' exp
      ected
          [javac] }
          [javac] ^
          [javac] 8 errors
      
      BUILD FAILED
      C:\hibernateTutorial\build.xml:21: Compile failed; see the compiler error output
       for details.
      
      Total time: 2 seconds
      C:\hibernateTutorial>
      EventManagerServlet code is:
      package events;
      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.io.*;
      import util.HibernateUtil; 
      import java.util.*;
      
      public class EventManagerServlet extends HttpServlet 
      {
      protected void doGet(HttpServletRequest request,HttpServletResponse response)
      throws ServletException, IOException 
      {
      SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");
      try 
      {    
      HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();   
      PrintWriter out = response.getWriter();
      out.println("<html><head><title>Event Manager</title></head><body>");
      if ( "store".equals(request.getParameter("action"))) 
      {
      String eventTitle = request.getParameter("eventTitle");
      String eventDate = request.getParameter("eventDate");
      if ( "".equals(eventTitle) || "".equals(eventDate) ) 
      {
      out.println("<b><i>Please enter event title and date.</i></b>");
      }
      else 
      {
      createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
      out.println("<b><i>Added event.</i></b>");
      }
      }
      printEventForm(out);
      listEvents(out, dateFormatter);
      out.println("</body></html>");
      out.flush();
      out.close();        
      HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
      private void printEventForm(PrintWriter out) 
      {
      out.println("<h2>Add new event:</h2>");
      out.println("<form>");
      out.println("Title: <input name='eventTitle' length='50'/><br/>");
      out.println("Date (e.g. 24.12.2009): <input name='eventDate' length='10'/><br/>");
      out.println("<input type='submit' name='action' value='store'/>");
      out.println("</form>");
      }
      
      private void listEvents(PrintWriter out,SimpleDateFormat dateFormatter) 
      {
      List result=HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(Event.class).list();
      if(result.size()>0) 
      {
      out.println("<h2>Events in database:</h2>");
      out.println("<table border='1'>");
      out.println("<tr>");
      out.println("<th>Event title</th>");
      out.println("<th>Event date</th>");
      out.println("</tr>");
      for(Iterator it = result.iterator();it.hasNext();) 
      {
      Event event = (Event) it.next();
      out.println("<tr>");
      out.println("<td>" + event.getTitle() + "</td>");
      out.println("<td>"+dateFormatter.format(event.getDate()) + "</td>");
      out.println("</tr>");
      }
      out.println("</table>");
      }
      }
      protected void createAndStoreEvent(String title,Date theDate) 
      {
      Event theEvent = new Event();
      theEvent.setTitle(title);
      theEvent.setDate(theDate);
      HibernateUtil.getSessionFactory().getCurrentSession().save(theEvent);
      }
      } 
      catch (Exception ex) 
      {
      HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
      throw new ServletException(ex);
      }
      }
      }
      Kindly suggest anyone.

      Great Regards
      -S.Singh

      Edited by: shobhit_onprob on Apr 22, 2008 11:46 AM