title: How to fetch data from multiple table query using hibernate?
body: <p>I am developing a simple application using Spring &amp; Hibernate. <strong>IDE :Eclipse</strong></p>
  
  <p>I want to show schedule of student.</p>
  
  <p>Schedule uses Student,Subject,Exam, &amp; Class tables.</p>
  
  <p>Schedule contains: student name, roll no, subject, class, exam, from time, to time &amp; date.</p>
  
  <p>I have written a query (works with > 1 table) which will return me a record, &amp; this record will be shown as schedule.</p>
  
  <p>No problems with query (I have printed the object on console).</p>
  
  <p>I am getting a NumberFormatException on my .jsp while retrieving records from list(list is sent from Controller )</p>
  
  <p><strong>1)</strong> Is it a right way to retrieve the multiple table values from list on jsp ??  Please suggest right way if this one is wrong.</p>
  
  <p><strong>2)</strong> Any other Changes in any part of following codes, which will able to fulfill my needs??</p>
  
  <p><strong>3)</strong> Any other ways for doing same thing..?? </p>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>    exception
  
  org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/studentschedule.jsp at line 301
  
  298:                &lt;/tr&gt;
  299:                &lt;c:forEach items="${scheduleList}" var="var"&gt;
  300:                &lt;tr&gt;
  301:                    &lt;td&gt;&lt;b&gt;${var.firstname }&lt;/b&gt;&lt;/td&gt;
  302:                    &lt;td&gt;&lt;b&gt;${var.roll }&lt;/b&gt;&lt;/td&gt;
  303:                    &lt;td&gt;&lt;b&gt;${var.subjectname }&lt;/b&gt;&lt;/td&gt;
  304:                    &lt;td&gt;&lt;b&gt;${var.classname }&lt;/b&gt;&lt;/td&gt;
  
  
  Stacktrace:
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
  org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
  org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1265)
  org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1016)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:965)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:859)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:883)
  org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:781)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  
  root cause
  
  java.lang.NumberFormatException: For input string: "firstname"
  java.lang.NumberFormatException.forInputString(Unknown Source)
  java.lang.Integer.parseInt(Unknown Source)
  java.lang.Integer.parseInt(Unknown Source)
  javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166)
  javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46)
  javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
  org.apache.el.parser.AstValue.getValue(AstValue.java:169)
  org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
  org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:985)
  org.apache.jsp.pages.studentschedule_jsp._jspx_meth_c_005fforEach_005f0(studentschedule_jsp.java:459)
  org.apache.jsp.pages.studentschedule_jsp._jspService(studentschedule_jsp.java:364)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
  org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
  org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1265)
  org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1016)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:965)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:859)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:883)
  org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:781)
  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.25 logs.
  </code></pre>
  
  <p><strong>Query+code</strong> is as follows.</p>
  
  <p>AdminStudentDaoImpl.java</p>
  
  <pre><code>@Override
  public List&lt;Student&gt; getStudentSchedule(int a) {
      // TODO Auto-generated method stub
  
      List&lt;Student&gt; u=hibernatetemplate.find("select stud.firstname,stud.roll,sub.subjectname,cls.classname,exam.exam_name,exam.from_time,exam.to_time,exam.exam_date from Student stud,Subject sub,Classs cls,Exam exam where exam.classs=cls.id and exam.subject=sub.id and sub.classs=cls.id and stud.classs=cls.id and stud.roll="+a);
  
      return u;   
  }
  </code></pre>
  
  <p>Domain (Tables) are as follows:</p>
  
  <p>student</p>
  
  <pre><code>@Entity
  @Table(name="student")
  public class Student {
  
  @Id
  @GeneratedValue
  @Column(name="id")
  private int id;
  @Column(name="roll_no")
  private int roll;
  @Column(name="firstname")
  private String firstname;
  @Column(name="lastname")
  private String lastname;
  @Column(name="dob")
  private String dob;
  @Column(name="email")
  private String email;
  @Column(name="contactno")
  private String contactno;
  @ManyToOne
  private Classs classs;
  
      Getters &amp; Setters....... 
      }
  </code></pre>
  
  <p>class</p>
  
  <pre><code>@Entity
  @Table(name="class")
  
  public class Classs {
  
  @Id
  @GeneratedValue
  @Column(name="id")
  private int id;
      @Column(name="classname")
  private String classname;
      Getters &amp; Setters.....
  }
  </code></pre>
  
  <p>Exam</p>
  
  <pre><code>@Entity
  @Table(name="exam")
  public class Exam {
  
  @Id
  @GeneratedValue
  @Column(name="id")
  private int id;
  @Column(name="exam_name")
  private String exam_name;
  
  @Column(name="exam_date")
  private String exam_date;
  
  @Column(name="from_time")
  private String from_time;
  
  @Column(name="to_time")
  private String to_time;
  
  @ManyToOne
  private Subject subject;
  
  @ManyToOne
  private Classs classs;
  
      Getters &amp; Setters.....
  }
  </code></pre>
  
  <p>Subject</p>
  
  <pre><code>@Entity
  @Table(name="subject")
  public class Subject {
  
      @Id
      @GeneratedValue
  
      @Column(name="id")
      private int id;
  
      @Column(name="subjectname")
      private String subjectname;
  
      @ManyToOne
      private Classs classs;
  
              Getters &amp; Setters.....
  }
  </code></pre>
  
  <p>In Controller i have written code like this :</p>
  
  <pre><code>@RequestMapping(value="schedule" ,method=RequestMethod.GET)
  public ModelAndView schedule(@ModelAttribute("attribute") Student student,BindingResult result,HttpSession session)throws Exception
  {
      int roll=Integer.parseInt((String) session.getAttribute("username"));
      System.out.println("roll no is========="+roll);
      List&lt;Student&gt; stud = adminstudentdao.getStudentSchedule(roll);
      System.out.println("list is========="+stud);
      ModelMap map=new ModelMap();
      map.addAttribute("scheduleList",stud);
      return new ModelAndView("studentschedule",map);
  }
  </code></pre>
  
  <p><strong>Jsp</strong>:</p>
  
  <pre><code>&lt;table border="0" width="100%" cellpadding="0" cellspacing="0" id="schedule-table"&gt;
              &lt;tr&gt;
  
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;Student name&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;Roll number&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;Subject&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;Class&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;exam&lt;/a&gt;&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;from time&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;to time&lt;/th&gt;
                  &lt;th class="table-header-repeat line-left minwidth-1"&gt;&lt;a href=""&gt;date&lt;/th&gt;
  
              &lt;/tr&gt;
               &lt;c:if test="${empty scheduleList}"&gt;
                     &lt;tr&gt;
                           &lt;td colspan="8"&gt;&lt;b&gt;No Results found&lt;/b&gt;&lt;/td&gt;
                     &lt;/tr&gt;
               &lt;/c:if&gt;
              &lt;c:forEach items="${scheduleList}" var="var"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;b&gt;${var.firstname }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.roll }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.subjectname }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.classname }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.exam_name }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.from_time }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.to_time }&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;b&gt;${var.exam_date }&lt;/b&gt;&lt;/td&gt;
  
  
              &lt;/tr&gt;
              &lt;/c:forEach&gt;
  
              &lt;/table&gt;
  </code></pre>