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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate works first few times, then stops
PostPosted: Mon Apr 25, 2011 8:19 am 
Newbie

Joined: Thu Apr 21, 2011 5:25 pm
Posts: 2
Hi, I've just uploaded a very simple web app that uses hibernate via a war file to my webserver:
http://www.colin-java.co.uk/BANK
The first couple of times I loaded the page above, it was fine, and it correctly displayed some of the contents of the User (MySQL) table.

But now when I load it, I get this error...
Code:
HTTP Status 500 -

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 25

null

Stacktrace:
   org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   sun.reflect.GeneratedMethodAccessor6469.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
   java.security.AccessController.doPrivileged(Native Method)
   javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
   org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
   org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
root cause

java.lang.NullPointerException
   org.apache.jsp.index_jsp._jspService(index_jsp.java:77)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   sun.reflect.GeneratedMethodAccessor6469.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
   java.security.AccessController.doPrivileged(Native Method)
   javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
   org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
   org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)


The index.jsp page is shown below:
Code:
<%@page import="bank.User"%>
<%@page import="java.util.List"%>
<%@page import="bank.BankHelper"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <%
        BankHelper helper = new BankHelper();
        List<User> users = helper.getUsers();

        for(User user : users)            //  **********  LINE 25 ************
        {
            out.println("user is "+user.getSurname()+"<BR>");
        }
        %>
    </body>
</html>


So it appears that 'users' on line 23 is null.

If I display the BankHelper class to look at the getUsers method,
perhaps this is the problem...

Code:
package bank;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class BankHelper
{

    Session session = null;

    public BankHelper()
    {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public List<User> getUsers()
    {
        List<User> users = null;

        try
        {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from User as user");
            users = q.list();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        return users;
    }
}


Can anyone help figure out what I'm doing wrong, I don't like it when things work first time, but not after.
Any help is much appreciated. Thanks


Top
 Profile  
 
 Post subject: Re: Hibernate works first few times, then stops
PostPosted: Mon Apr 25, 2011 5:21 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The users object probably is null because there is a problem executing the query in BankHelper.getUsers(). It would be helpful if you posted the log that e.printStackTrace() produces.


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

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.